From 449361880191f077e810299d2547a6f594c783b4 Mon Sep 17 00:00:00 2001 From: Logan Williams Date: Thu, 12 May 2022 13:02:14 +0000 Subject: [PATCH] Synchronizing channels will update other info for existing channels --- app.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index c22a137..3ebc673 100644 --- a/app.py +++ b/app.py @@ -60,11 +60,17 @@ def sync_channels(args): channel = ( session.query(Channel) .filter_by( - platform_id=str(platform_id), platform=c["platform"], url=c["url"] + platform_id=str(platform_id), platform=str(c["platform"]) ) .first() ) + if not channel: + channel = session.query(Channel).filter_by(platform=str(c["platform"]), url=str(c["url"])).first() + + if not channel and c["screenname"] != '' and c["screenname"] is not None: + channel = session.query(Channel).filter_by(platform=str(c["platform"]), screenname=str(c["screenname"])).first() + if not channel: channel = Channel(**c, source="researcher") logger.debug(f"{channel} does not exist, adding") @@ -74,6 +80,26 @@ def sync_channels(args): wks.update_cell(row, 1, channel.id) time.sleep(1) + else: + logger.info(f"Channel found, updating channel {channel}") + channel.name = c["name"] + channel.category = c["category"] + channel.platform = c["platform"] + channel.url = c["url"] + channel.screenname = c["screenname"] + channel.country = c["country"] + channel.influencer = c["influencer"] + channel.public = c["public"] + channel.chat = c["chat"] + channel.notes = c["notes"] + channel.source = "researcher" + + session.flush() + session.commit() + + wks.update_cell(row, 1, channel.id) + time.sleep(1) + else: channel = session.query(Channel).filter_by(id=int(c["id"])).first() @@ -88,6 +114,7 @@ def sync_channels(args): channel.public = c["public"] channel.chat = c["chat"] channel.notes = c["notes"] + channel.source = "researcher" session.flush() session.commit() @@ -202,6 +229,7 @@ if __name__ == "__main__": logger.add("logs/channel-info.log", level="TRACE", rotation="100 MB") scrape_channel_info(args) elif args.command == "transform": + logger.add("logs/transform.log", level="TRACE", rotation="100 MB") transform(args) else: logger.error(f"Unrecognized command {args.command}")