How to filter tweets (status) with tweepy (Cursor)

Asked

Viewed 364 times

2

I took from the book "Mastering social media Mining with python" the code below, which saves all a user’s tweets in JSON format. But I would like you to save in json only tweets of a certain date. How to do?

This is the code that saves all tweets:

fname2=dirname
fname2+= "/user_timeline.jsonl"

with open(fname2, 'w') as f:
    for page in Cursor(client.user_timeline, screen_name=screen_name, count=200).pages(16):
        for status in page:
            f.write(json.dumps(status._json)+"\n")

This is the structure of JSON: https://gist.github.com/dev-techmoe/ef676cdd03ac47ac503e856282077bf2

How can I make this filter? Another detail is that in JSON there is a tweet after another between {} but there is no key for it (without "Tweet": {.....})

Thank you!

  • 1

    What do you know about Python? Do you know what exactly the code you posted is doing? Have you tried anything?

1 answer

1

this code converts the string to a date:

from dateutil.parser import parse

date = parse(date)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.