Synchronizing channels will update other info for existing channels

This commit is contained in:
Logan Williams
2022-05-12 13:02:14 +00:00
parent ab482443db
commit 4493618801

30
app.py
View File

@@ -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}")