Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
| Comment: | Make this actually work for lots of favs
Don't know if somehting changed or this was just always semi-broken Previously this assumed that the response returned all favs for a site This does mean get_favs now returns an array of items (makes more sense) |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | trunk | master |
| Files: | files | file ages | folders |
| SHA3-256: |
09c69470368aa60945a1a3d1d277eef3 |
| User & Date: | base@atomicules.co.uk 2017-03-12 14:54:59 |
|
2017-03-12
| ||
| 14:54 |
Make this actually work for lots of favs
Don't know if somehting changed or this was just always semi-broken Previously this assumed that the response returned all favs for a site This does mean get_favs now returns an array of items (makes more sense) | |
|
2015-06-20
| ||
| 18:40 |
Add basic caching to speed up adding new bookmarks
Since have to (well should do, to be nice) rate limit quite a lot it can Some things I have to do (note to self): - Check for success on Pinboard add before adding to cache | |
Changes to stackexchange-favs-to-pinboard.rb.
| ︙ | ︙ | |||
23 24 25 26 27 28 29 | def parse(response_string) #Seems like Ruby automatically handles gzip compression now. No need to decompress. parsed = JSON.parse(response_string) end def get_favs(site, id) | > > > > > | | | > > > > > > | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
def parse(response_string)
#Seems like Ruby automatically handles gzip compression now. No need to decompress.
parsed = JSON.parse(response_string)
end
def get_favs(site, id)
puts "Fetching favs for #{site}"
has_more = true
items = []
page = 1
while has_more
response = open("https://api.stackexchange.com/2.2/users/#{id}/favorites?order=desc&sort=added&pageSize=100&page=#{page}&site=#{site}")
#Use response.read not .string as some returns are large enough to go to a temp file
parsed = parse(response.read)
items += parsed["items"]
has_more = parsed["has_more"]
page += 1
end
puts "#{items.length} favs"
items
end
class Pinboard
@@logger = Logger.new(STDOUT)
@@logger.level = Logger::INFO
@@rate_limit = 3
|
| ︙ | ︙ | |||
95 96 97 98 99 100 101 |
if File.exists?(cache_file)
cache = JSON.parse(File.read(cache_file))
else
cache = {}
end
parsed = get_sites(StackID)
parsed["items"].each do |site|
| | | | 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
if File.exists?(cache_file)
cache = JSON.parse(File.read(cache_file))
else
cache = {}
end
parsed = get_sites(StackID)
parsed["items"].each do |site|
favs = get_favs(site["site_url"].sub("http://", "").sub("https://", "").sub(".stackexchange", "").sub(".com", ""), site["user_id"])
#Don't make more than 30 requests per second
sleep (1.0/30)
favs.each do |fav|
title = fav["title"]
tags = fav["tags"]
link = fav["link"]
#Check cache to see if already added to pinboard
unless cache.has_key?(link)
#Need to unescape so can re-escape in Pinboard code
#Still want no default replace, just in case cache doesn't exist
|
| ︙ | ︙ |