Aupajo / almanack

Aggregate iCal and Google Calendar events. Pluggable or standalone app. UI optional and 100% customisable.
MIT License
54 stars 25 forks source link

Meetup API throttling #17

Closed popey closed 5 years ago

popey commented 7 years ago

I've added a bunch (possibly too many?) meetup events to my config.ru. I'm getting throttled by the meetup api, and their advice is to simply add a pause between one call and the next. Perhaps this is something that could be done in almanack? Otherwise I guess I just have to reduce the number of meetups I'm following?

Aupajo commented 7 years ago

@popey What I've done is use multiple API keys and just cycle them:

Almanack.config do |c|
  meetup_keys = %w( MEETUP_KEY_1 MEETUP_KEY_2 MEETUP_KEY_3 ).cycle

  # Will use the first key
  c.add_meetup_group(group_urlname: 'WikiHouse-NZ', meetup_api_key: meetup_keys.next)
  # Will use the second key
  c.add_meetup_group(group_urlname: 'Design-Thinking-Group', meetup_api_key: meetup_keys.next)
  # Will use the third key
  c.add_meetup_group(group_urlname: 'CHC-JS', meetup_api_key: meetup_keys.next)
  # Will use the first key
  c.add_meetup_group(group_urlname: 'ISIG-Christchurch-NZ', meetup_api_key: meetup_keys.next)
  # Etc.
end

Hope that helps!

Aupajo commented 5 years ago

The combination of caching and multiple API keys works well.

Almanack.config do |c|
  # Don't fetch event information more than once every 15 minutes
  c.cache_responses = true
  c.cache_expiry = ENV.fetch('CACHE_DURATION_IN_SECONDS') { 900 }.to_i

  meetup_keys = %w( MEETUP_KEY_1 MEETUP_KEY_2 ).cycle
  meetup_groups = %w(
    WikiHouse-NZ
    CHC-JS
    ISIG-Christchurch-NZ
    Design-Thinking-Group
  )

  meetup_groups.each do |group|
    c.add_meetup_group(group_urlname: group, meetup_api_key: meetup_keys.next)
  end
end