From 317531b09845ed9a2c0601e1af2e6a003c582054 Mon Sep 17 00:00:00 2001 From: newt Date: Wed, 9 Oct 2024 18:02:31 +0100 Subject: [PATCH] Fix twitter.py to read new directories --- .../computer science and social media/twitter.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/coursework/royal institute computer science masterclass 2021/computer science and social media/twitter.py b/coursework/royal institute computer science masterclass 2021/computer science and social media/twitter.py index 0651639..27a433a 100644 --- a/coursework/royal institute computer science masterclass 2021/computer science and social media/twitter.py +++ b/coursework/royal institute computer science masterclass 2021/computer science and social media/twitter.py @@ -1,11 +1,13 @@ import csv +import os class Account: def __init__(self, csvfile): self.handle = csvfile[:-4] self.bio = '' self._tweets = [] - with open(csvfile, 'r',encoding='utf-8') as file: + filePath = '{0}/{1}'.format(os.path.dirname(os.path.realpath(__file__)), csvfile) + with open(filePath, 'r',encoding='utf-8') as file: reader = csv.reader(file) first_row = 1 for row in reader: @@ -30,4 +32,4 @@ class Tweet: self.text = tweet[0] self.likes = int(tweet[1]) self.retweets = int(tweet[2]) - self.date_time = tweet[3] \ No newline at end of file + self.date_time = tweet[3]