deprem-yardim-backend icon indicating copy to clipboard operation
deprem-yardim-backend copied to clipboard

feat: Initial instagram integration implementation

Open pyneda opened this issue 2 years ago • 1 comments

This PR implements an initial implementation of a similar functionality than the existing for Twitter, but for Instagram.

Few notes:

  • Hashtags to follow can be defined from the admin interface
  • It uses the instagrapi library to handle the communication with Instagram
  • It allows to get data without authentication (even though Instagram may block us), authenticate with username and password provided via settings (this might fail in some cases due to Instagram requiring a 2FA challenge) or to create a session handling the challenge via a django management command create_instagram_session and saving the session data to the database for further use
  • How many recent posts should be gathered per each hashtag can be configured via settings
  • It still uses the existing Address/Location models used for Twitter, so we can keep using the same endpoints
  • Also uses the ask_to_zekai functionality to get the Location/Address, even though from Instagram we can get the address and coordinates from the posts
  • The LocationSerializer includes a new instagram_raw field. It could also be made to just use the raw field for both Twitter/Instagram getting the serializer dynamically

Update: I have noted that most of the people asking for help on Instagram does it on specific posts comments (such as: https://www.instagram.com/p/CoX7F0Lt0F2/), due to this I have also added the following functionality to the PR:

  • Allow to define posts whose comments should be tracked
  • Fetch and save the comments that contain certain words (same as used on the Twitter query) and analyze them with zekai to get the Address/Location
  • Have also made some of the ask_to_zekai functionality a bit more reusable under applications/core/helpers.py. Not added it into the twitter side due to possible merge conflicts later.
  • Have not added the comments to the APIs yet, as I'm not sure how this is wanted, but the serializer is ready and should be trivial to add.

pyneda avatar Feb 07 '23 15:02 pyneda

I have seen the whole app structure changed since I started implementing this feature. If you could confirm you are interested in using Instagram as a data source, I could update it to fit with the current implementation.

@hmert @ferhatbostanci @eserozvataf @ahmetkotan

pyneda avatar Feb 08 '23 20:02 pyneda