罗俊辉 7 ماه پیش
والد
کامیت
5adc7955f1
1فایلهای تغییر یافته به همراه38 افزوده شده و 37 حذف شده
  1. 38 37
      getTencentReadDetails.py

+ 38 - 37
getTencentReadDetails.py

@@ -54,6 +54,7 @@ class getTencentAccountReadDetail(object):
         :return:
         """
         yesterday = (datetime.today() - timedelta(days=daysCount)).strftime('%Y-%m-%d')
+        print(yesterday)
         tencentUrl = "https://api.weixin.qq.com/datacube/getarticlesummary?access_token={}".format(accessToken)
         response = requests.post(
             url=tencentUrl,
@@ -63,6 +64,7 @@ class getTencentAccountReadDetail(object):
             },
             timeout=10
         )
+        print(response.json())
         return response.json()
 
     @classmethod
@@ -107,42 +109,41 @@ class getTencentAccountReadDetail(object):
         :return:
         """
         accountList = cls.generateAccountList()
-        for i in range(2, 32):
-            for account in tqdm(accountList):
-                try:
-                    accountName = account['name']
-                    ghId = account['ghId']
-                    accessToken = cls.getAccountAccessToken(ghId=ghId)
-                    detailList = cls.getAccountYesterdayReadInfo(accessToken=accessToken, daysCount=i).get('list', [])
-                    if detailList:
-                        infoList = []
-                        for item in detailList:
-                            info = (
-                                ghId,
-                                accountName,
-                                item['ref_date'],
-                                item['user_source'],
-                                item['msgid'].split("_")[0],
-                                item['msgid'].split("_")[1],
-                                item['title'],
-                                item['int_page_read_user'],
-                                item['int_page_read_count'],
-                                item['ori_page_read_user'],
-                                item['ori_page_read_count'],
-                                item['share_user'],
-                                item['share_count'],
-                                item['add_to_fav_user'],
-                                item['add_to_fav_count']
-                            )
-                            infoList.append(info)
-                        cls.saveIntoDataBase(infoTupleList=infoList)
-                except Exception as e:
-                    log = {
-                        "error": str(e),
-                        "msg": "更新账号文章失败",
-                        "accountInfo": account
-                    }
-                    print(log)
+        for account in tqdm(accountList):
+            try:
+                accountName = account['name']
+                ghId = account['ghId']
+                accessToken = cls.getAccountAccessToken(ghId=ghId)
+                detailList = cls.getAccountYesterdayReadInfo(accessToken=accessToken, daysCount=1).get('list', [])
+                if detailList:
+                    infoList = []
+                    for item in detailList:
+                        info = (
+                            ghId,
+                            accountName,
+                            item['ref_date'],
+                            item['user_source'],
+                            item['msgid'].split("_")[0],
+                            item['msgid'].split("_")[1],
+                            item['title'],
+                            item['int_page_read_user'],
+                            item['int_page_read_count'],
+                            item['ori_page_read_user'],
+                            item['ori_page_read_count'],
+                            item['share_user'],
+                            item['share_count'],
+                            item['add_to_fav_user'],
+                            item['add_to_fav_count']
+                        )
+                        infoList.append(info)
+                    cls.saveIntoDataBase(infoTupleList=infoList)
+            except Exception as e:
+                log = {
+                    "error": str(e),
+                    "msg": "更新账号文章失败",
+                    "accountInfo": account
+                }
+                print(log)
 
 
 def job():
@@ -155,7 +156,7 @@ def job():
 
 
 if __name__ == '__main__':
-    schedule.every().day.at("08:15").do(Functions().job_with_thread, job())
+    schedule.every().day.at("08:15").do(Functions().job_with_thread, job)
 
     while True:
         schedule.run_pending()