Changeset 1495
- Timestamp:
- 10/20/07 18:59:27 (1 year ago)
- Files:
-
- publicize-posts/publicize-posts.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
publicize-posts/publicize-posts.rb
r1494 r1495 27 27 end 28 28 29 def time_test30 t = Time.at( 1192485440 )31 puts t.strftime( "%Y-%m-%dT%H:%M:%SZ" )32 end33 34 29 # loop over links 35 30 # foreach link … … 42 37 # build API request 43 38 # convert date to ISO 8601 date 44 # correctly encode URL, name, and notes39 # correctly encode URL, description, and notes 45 40 # send API request and capture return value 46 41 # pause for 2 seconds to avoid throttling … … 49 44 # <DD>wow. A watch that requires oil changes!? 50 45 46 def convert_date( d ) 47 t = Time.at( d.to_i ) 48 return t.strftime( "%Y-%m-%dT%H:%M:%SZ" ) 49 end 50 51 def convert_tags( tag ) 52 default_tag = "feedmelinks" # FIXME: make this some kind of top-level configurable constant 53 tags = tag.gsub /,/, ' ' 54 tags = tags.gsub /(import2|imported)/, '' 55 tags = tags.gsub /^ /, '' 56 tags = tags.gsub /\s+/, ' ' 57 tags = tags.gsub /^$/, default_tag 58 end 59 51 60 def parse_links 52 53 default_tag = "feedmelinks"54 61 File.open( "out" ).grep /post/ do |line| 55 62 56 if line =~ /href="([^"]+)" add_date="(\d+)" tags="([^"]+)" /63 if line =~ /href="([^"]+)" add_date="(\d+)" tags="([^"]+)">([^<]+)</ 57 64 url = "#$1" 58 date = "#$2" 59 tags = "#$3".gsub /,/, ' ' 60 tags = tags.gsub /(import2|imported)/, '' 61 tags = tags.gsub /^ /, '' 62 tags = tags.gsub /\s+/, ' ' 63 tags = tags.gsub /^$/, default_tag 64 65 puts tags 65 date = convert_date( "#$2" ) 66 tags = convert_tags( "#$3" ) 67 description = "#$4" 66 68 end 67 69 if line =~ /<note>(.*)/