nikosbosse / Metaculus-Twitter-bot

17 stars 4 forks source link

Add a chart of historical predictions to each tweet + automatically get list of relevant questions #7

Closed edomt closed 2 years ago

edomt commented 2 years ago

Implements the following:

  1. Parse the lower and upper bound of the time series
  2. Produce a matplotlib chart with a design similar to Metaculus
  3. Save the chart locally as a tempfile
  4. Upload the chart to Twitter's API and then include it in the tweet

In order to implement (4), I've had to switch to using the Tweepy v1.1 API – from my understanding of their documentation, uploading images isn't possible yet with the v2 API.

@nikosbosse Overall you'll probably need to test & debug this a little bit before merging, because I'm not sure everything works, especially in terms of API authentication and image upload 🤷🏻‍♂️

nikosbosse commented 2 years ago

Thanks, this is really cool! I found this in terms of images and the api v2: https://stackoverflow.com/questions/70129448/how-to-create-tweet-using-tweepy-api-v-2 - Incidentally I think the way you implemented it (uploading image and getting the id separately) is already the way to do it in v2. For switching to v1 I'd have to get the developer account upgraded to "elevated access" which may take a while

EDIT: So apparently the post on SO was not well informed. You're right, it doesn't seem possible at the moment. I'm currently applying for API v1 access

edomt commented 2 years ago

The YAML file now includes:

# Questions to include in the alerts
# All questions in these projects will be included
projects:
  - 1426
# All questions below will be included
questions:
  - 2797
  - 9743

And I've added a general filter on question types:

# Questions that don't meet these criteria will be excluded
filters:
  minimum_hours: 24 # Minimum number of hours since first forecast
  minimum_forecasts: 10 # Minimum number of forecasts made
  types: # Types of questions handled by the bot
    - binary

Closes #4

nikosbosse commented 2 years ago

Amazing, thanks a lot! I also just got elevated developer access so we can start using the images. Metaculus also might develop their own shareable images in the near future if we're lucky.

I played around with the colors, trying to make them less opaque - not sure that did more good than harm. Maybe it would be nice to have a ribbon for the uncertainty, rather than just two lines. But I nevertheless think it's already much nicer and I deployed it as is.

Probably the main thing to focus on next is to avoid duplicating tweets (as there now is quite a large number of questions). One possibility would be to check whether the function call 6h ago would have retweeted something, and if so, not to retweet it (or a slightly more sophisticated version of that).