From ea49ddabcc669a9b50d9b0e2c516576808b8c8c6 Mon Sep 17 00:00:00 2001 From: arlou Date: Thu, 14 Oct 2021 10:39:36 +0800 Subject: [PATCH] Fixing problem on type conversion convert variable type from string to datetime --- crawler.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crawler.py b/crawler.py index a0d71ed..557301a 100644 --- a/crawler.py +++ b/crawler.py @@ -19,8 +19,10 @@ def calculateScore(repoData): iScore += repoData["forks_count"] * 5; #Caculate days elapsed since the repo was created and last updated - repoUpdateDate = repoData['updated_at'] - repoCreateDate = repoData['created_at'] + repoUpdateDate = datetime.strptime(repoData['updated_at'],"%Y-%m-%dT%H:%M:%SZ") + repoUpdateDate = repoUpdateDate.replace(tzinfo=timezone.utc) + repoCreateDate = datetime.strptime(repoData['created_at'],"%Y-%m-%dT%H:%M:%SZ") + repoCreateDate = repoCreateDate.replace(tzinfo=timezone.utc) currentDate = datetime.now(timezone.utc) iDaysSinceLastUpdate = currentDate - repoUpdateDate; iDaysSinceCreation = currentDate - repoCreateDate; @@ -155,4 +157,4 @@ def calculateScore(repoData): #write the content in a json file with open("repos.json", "w") as f: json.dump(finalData, f, indent=4,sort_keys=False,default=str) - print("repos.json file written") \ No newline at end of file + print("repos.json file written")