this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

favorites command now populates favorited_by table, closes #14

+16 -10
+8 -5
twitter_to_sqlite/cli.py
··· 150 150 "Save tweets favorited by specified user" 151 151 auth = json.load(open(auth)) 152 152 session = utils.session_for_auth(auth) 153 + profile = utils.get_profile(session, user_id, screen_name) 153 154 db = sqlite_utils.Database(db_path) 154 155 with click.progressbar( 155 156 utils.fetch_favorites(session, user_id, screen_name), 156 157 label="Importing favorites", 157 158 show_pos=True, 158 159 ) as bar: 159 - utils.save_tweets(db, bar) 160 + utils.save_tweets(db, bar, favorited_by=profile["id"]) 160 161 161 162 162 163 @cli.command(name="user-timeline") ··· 227 228 def save_chunk(db, chunk): 228 229 utils.save_tweets(db, chunk) 229 230 # Record who's timeline they came from 230 - db["timeline_tweets"].upsert_all([{ 231 - "user": profile["id"], 232 - "tweet": tweet["id"] 233 - } for tweet in chunk], pk=("user", "tweet"), foreign_keys=("user", "tweet")) 231 + db["timeline_tweets"].upsert_all( 232 + [{"user": profile["id"], "tweet": tweet["id"]} for tweet in chunk], 233 + pk=("user", "tweet"), 234 + foreign_keys=("user", "tweet"), 235 + ) 236 + 234 237 chunk = [] 235 238 for tweet in bar: 236 239 chunk.append(tweet)
+8 -5
twitter_to_sqlite/utils.py
··· 87 87 88 88 def fetch_home_timeline(session): 89 89 yield from fetch_timeline( 90 - session, 91 - "https://api.twitter.com/1.1/statuses/home_timeline.json", 92 - {}, 93 - sleep=1, 90 + session, "https://api.twitter.com/1.1/statuses/home_timeline.json", {}, sleep=1 94 91 ) 95 92 96 93 ··· 194 191 ) 195 192 196 193 197 - def save_tweets(db, tweets): 194 + def save_tweets(db, tweets, favorited_by=None): 198 195 ensure_tables(db) 199 196 for tweet in tweets: 200 197 transform_tweet(tweet) ··· 216 213 save_tweets(db, nested) 217 214 db["users"].upsert(user, pk="id", alter=True) 218 215 table = db["tweets"].upsert(tweet, pk="id", alter=True) 216 + if favorited_by is not None: 217 + db["favorited_by"].upsert( 218 + {"tweet": tweet["id"], "user": favorited_by}, 219 + pk=("user", "tweet"), 220 + foreign_keys=("tweet", "user"), 221 + ) 219 222 if extended_entities and extended_entities.get("media"): 220 223 for media in extended_entities["media"]: 221 224 # TODO: Remove this line when .m2m() grows alter=True