MCPcopy Create free account
hub / github.com/dataabc/weibo-crawler / insert_or_update_user

Function insert_or_update_user

util/csvutil.py:6–24  ·  view source on GitHub ↗

插入或更新用户csv。不存在则插入,最新抓取微博id不填,存在则先不动,返回已抓取最新微博id和日期

(logger, headers, result_data, file_path)

Source from the content-addressed store, hash-verified

4
5
6def insert_or_update_user(logger, headers, result_data, file_path):
7 """插入或更新用户csv。不存在则插入,最新抓取微博id不填,存在则先不动,返回已抓取最新微博id和日期"""
8 first_write = True if not os.path.isfile(file_path) else False
9 if os.path.isfile(file_path):
10 # 文件已存在,直接查看有没有,有就直接return了
11 with open(file_path, 'r', encoding='utf-8-sig') as f:
12 for line in f:
13 if line.split(',')[0] == result_data[0][0]:
14 return line.split(',')[len(line.split(',')) - 1].replace('\n', '')
15
16 # 没有或者新建
17 result_data[0].append('')
18 with open(file_path, 'a', encoding='utf-8-sig', newline='') as f:
19 writer = csv.writer(f)
20 if first_write:
21 writer.writerows([headers])
22 writer.writerows(result_data)
23 logger.info('{} 信息写入csv文件完毕,保存路径: {}'.format(result_data[0][1], file_path))
24 return ''
25
26
27def update_last_weibo_id(userid, new_last_weibo_msg, file_path):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected