|
@@ -0,0 +1,154 @@
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+# @Author: wangkun
|
|
|
+# @Time: 2022/6/20
|
|
|
+import time
|
|
|
+
|
|
|
+import requests
|
|
|
+import urllib3
|
|
|
+from main.common import Common
|
|
|
+from main.feishu_lib import Feishu
|
|
|
+proxies = {"http": None, "https": None}
|
|
|
+
|
|
|
+
|
|
|
+class CopyUsersInfo:
|
|
|
+
|
|
|
+ # 备份表数据
|
|
|
+ @classmethod
|
|
|
+ def copyed_data(cls):
|
|
|
+ try:
|
|
|
+ data_list = []
|
|
|
+ lists = Feishu.get_values_batch("twitter", "WPJILC")
|
|
|
+ for i in lists:
|
|
|
+ for j in i:
|
|
|
+ # 过滤空的单元格内容
|
|
|
+ if j is None:
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ data_list.append(j)
|
|
|
+ return data_list
|
|
|
+ except Exception as e:
|
|
|
+ Common.logger().error("获取备份表数据异常:{}", e)
|
|
|
+
|
|
|
+ # 增加工作表,复制工作表、删除工作表。
|
|
|
+ @classmethod
|
|
|
+ def sheets_batch_update(cls):
|
|
|
+ """
|
|
|
+ https://open.feishu.cn/document/ukTMukTMukTM/uYTMzUjL2EzM14iNxMTN
|
|
|
+ """
|
|
|
+ url = "https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/shtcn6BYfYuqegIP13ORB6rI2dh/sheets_batch_update"
|
|
|
+ headers = {
|
|
|
+ "Authorization": "Bearer " + Feishu.get_token(),
|
|
|
+ "Content-Type": "application/json; charset=utf-8"
|
|
|
+ }
|
|
|
+ body = {
|
|
|
+ "requests": [
|
|
|
+ {
|
|
|
+ "copySheet": {
|
|
|
+ "source": {
|
|
|
+ "sheetId": "db114c"
|
|
|
+ },
|
|
|
+ "destination": {
|
|
|
+ "title": ""
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ try:
|
|
|
+ urllib3.disable_warnings()
|
|
|
+ r = requests.post(url=url, headers=headers, json=body, proxies=proxies, verify=False)
|
|
|
+ print(r.json())
|
|
|
+ # Common.logger().info("增加工作表,复制工作表、删除工作表:{}", r.json()["msg"])
|
|
|
+ except Exception as e:
|
|
|
+ Common.logger().error("增加工作表,复制工作表、删除工作表异常:{}", e)
|
|
|
+
|
|
|
+ # 复制用户信息
|
|
|
+ @classmethod
|
|
|
+ def copy_usersinfo(cls):
|
|
|
+ try:
|
|
|
+ user_list = Feishu.get_values_batch("twitter", "db114c")
|
|
|
+ for i in range(1, len(user_list[1:])):
|
|
|
+ uid = user_list[i][0]
|
|
|
+ key_word = user_list[i][1]
|
|
|
+ name = user_list[i][2]
|
|
|
+ screen_name = user_list[i][3]
|
|
|
+ person_url = user_list[i][4]
|
|
|
+ description = user_list[i][5]
|
|
|
+ location = user_list[i][6]
|
|
|
+ friends_count = user_list[i][7]
|
|
|
+ followers_count = user_list[i][8]
|
|
|
+ favourites_count = user_list[i][9]
|
|
|
+ listed_count = user_list[i][10]
|
|
|
+ statuses_count = user_list[i][11]
|
|
|
+ media_count = user_list[i][12]
|
|
|
+ display_url = user_list[i][13]
|
|
|
+ created_at = user_list[i][14]
|
|
|
+ profile_image_url = user_list[i][15]
|
|
|
+ profile_banner_url = user_list[i][16]
|
|
|
+ ext_has_nft_avatar = user_list[i][17]
|
|
|
+ verified = user_list[i][18]
|
|
|
+ created_time = user_list[i][19]
|
|
|
+ update_time = user_list[i][20]
|
|
|
+ # print(f"\n第{i}个用户信息")
|
|
|
+ # print(f"uid:{uid}")
|
|
|
+ # print(f"key_word:{key_word}")
|
|
|
+ # print(f"name:{name}")
|
|
|
+ # print(f"screen_name:{screen_name}")
|
|
|
+ # print(f"person_url:{person_url}")
|
|
|
+ # print(f"description:{description}")
|
|
|
+ # print(f"location:{location}")
|
|
|
+ # print(f"friends_count:{friends_count}")
|
|
|
+ # print(f"followers_count:{followers_count}")
|
|
|
+ # print(f"favourites_count:{favourites_count}")
|
|
|
+ # print(f"listed_count:{listed_count}")
|
|
|
+ # print(f"statuses_count:{statuses_count}")
|
|
|
+ # print(f"media_count:{media_count}")
|
|
|
+ # print(f"display_url:{display_url}")
|
|
|
+ # print(f"created_at:{created_at}")
|
|
|
+ # print(f"profile_image_url:{profile_image_url}")
|
|
|
+ # print(f"profile_banner_url:{profile_banner_url}")
|
|
|
+ # print(f"ext_has_nft_avatar:{ext_has_nft_avatar}, type:{type(ext_has_nft_avatar)}")
|
|
|
+ # print(f"verified:{verified}, type:{type(verified)}")
|
|
|
+ # print(f"created_time:{created_time}")
|
|
|
+ # print(f"update_time:{update_time}")
|
|
|
+ # print("\n")
|
|
|
+
|
|
|
+ if uid in cls.copyed_data():
|
|
|
+ Common.logger().info("用户信息已存在")
|
|
|
+ return
|
|
|
+ else:
|
|
|
+ Common.logger().info("开始拷贝第{}个用户信息", i)
|
|
|
+ time.sleep(1)
|
|
|
+ Feishu.insert_columns("twitter", "WPJILC", "ROWS", 1, 2)
|
|
|
+ values = [[uid,
|
|
|
+ key_word,
|
|
|
+ name,
|
|
|
+ screen_name,
|
|
|
+ person_url,
|
|
|
+ description,
|
|
|
+ location,
|
|
|
+ friends_count,
|
|
|
+ followers_count,
|
|
|
+ favourites_count,
|
|
|
+ listed_count,
|
|
|
+ statuses_count,
|
|
|
+ media_count,
|
|
|
+ display_url,
|
|
|
+ created_at,
|
|
|
+ profile_image_url,
|
|
|
+ profile_banner_url,
|
|
|
+ str(ext_has_nft_avatar),
|
|
|
+ str(verified),
|
|
|
+ created_time,
|
|
|
+ update_time]]
|
|
|
+ time.sleep(1)
|
|
|
+ Feishu.update_values("twitter", "WPJILC", "A2:U2", values)
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ Common.logger().error("复制用户信息异常:{}", e)
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == "__main__":
|
|
|
+ copy = CopyUsersInfo()
|
|
|
+ copy.sheets_batch_update()
|
|
|
+ # copy.copy_usersinfo()
|