Skip to content

Commit 4050d67

Browse files
authored
Add language_code to DB schema, and populate with languageCode from API response. (#195)
* Add language_code to DB schema, and populate with languageCode from API response. * add missing, line terminating comma in namedtuple field list * add langauge_code column name to insert statement
1 parent c7666b1 commit 4050d67

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

crowdtangle/db_functions.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ def upsert_posts(self, posts):
2525
'%(title)s,%(platform)s, %(platform_id)s, %(post_url)s, %(subscriber_count)s, '
2626
'%(type)s, %(updated)s, %(video_length_ms)s, %(image_text)s, %(legacy_id)s, '
2727
'%(caption)s, %(link)s, %(date)s, %(description)s, %(score)s, %(live_video_status)s, '
28-
'CURRENT_TIMESTAMP)')
28+
'%(language_code)s, CURRENT_TIMESTAMP)')
2929
insert_posts_query = (
3030
'''INSERT INTO posts(id, account_id, branded_content_sponsor_account_id, message, title,
3131
platform, platform_id, post_url, subscriber_count, type, updated, video_length_ms,
3232
image_text, legacy_id, caption, link, date, description, score, live_video_status,
33-
last_modified_time) VALUES %s ON CONFLICT (id) DO UPDATE SET id = EXCLUDED.id,
34-
account_id = EXCLUDED.account_id,
33+
language_code, last_modified_time) VALUES %s
34+
ON CONFLICT (id) DO UPDATE SET id = EXCLUDED.id, account_id = EXCLUDED.account_id,
3535
branded_content_sponsor_account_id = EXCLUDED.branded_content_sponsor_account_id,
3636
message = EXCLUDED.message, title = EXCLUDED.title, platform = EXCLUDED.platform,
3737
platform_id = EXCLUDED.platform_id, post_url = EXCLUDED.post_url,
@@ -40,7 +40,8 @@ def upsert_posts(self, posts):
4040
image_text = EXCLUDED.image_text, legacy_id = EXCLUDED.legacy_id,
4141
caption = EXCLUDED.caption, link = EXCLUDED.link, date = EXCLUDED.date,
4242
description = EXCLUDED.description, score = EXCLUDED.score,
43-
live_video_status = EXCLUDED.live_video_status, last_modified_time = CURRENT_TIMESTAMP
43+
live_video_status = EXCLUDED.live_video_status, language_code = EXCLUDED.language_code,
44+
last_modified_time = CURRENT_TIMESTAMP
4445
WHERE posts.id = EXCLUDED.id AND posts.updated < EXCLUDED.updated;''')
4546
psycopg2.extras.execute_values(cursor,
4647
insert_posts_query,

crowdtangle/process_crowdtangle_posts.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
'date',
3737
'description',
3838
'score',
39-
'live_video_status'])
39+
'live_video_status',
40+
'language_code'])
4041
AccountRecord = namedtuple('AccountRecord',
4142
['id',
4243
'account_type',
@@ -141,7 +142,8 @@ def process(self, item):
141142
date=item.get('date'),
142143
description=item.get('description'),
143144
score=item.get('score'),
144-
live_video_status=item.get('liveVideoStatus'))
145+
live_video_status=item.get('liveVideoStatus'),
146+
language_code=item.get('languageCode'))
145147

146148
account_list = [self.make_account_record(item['account'], post_updated)]
147149

sql/unified_schema.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ CREATE TABLE public.posts (
342342
description character varying,
343343
score double precision,
344344
live_video_status character varying,
345+
language_code character varying,
345346
last_modified_time timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
346347
CONSTRAINT account_id_fk FOREIGN KEY (account_id) REFERENCES public.accounts (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION,
347348
CONSTRAINT branded_content_sponsor_account_id_fk FOREIGN KEY (branded_content_sponsor_account_id) REFERENCES public.accounts (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION

0 commit comments

Comments
 (0)