-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
29 lines (24 loc) · 944 Bytes
/
app.py
File metadata and controls
29 lines (24 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import scrappers.scrappers as scrappers
from scrappers.scrappers import ScrapeTwitter
import datetime
import os
from dotenv import load_dotenv
load_dotenv()
# Use environment variables for credentials
username = os.getenv("TWITTER_USERNAME")
password = os.getenv("TWITTER_PASSWORD")
# Script to Scrape twitter data
query = "India Developping"
twitter = ScrapeTwitter((username, password), query=query)
login = twitter.login()
print(login["status"])
if login["status"] == "success":
data = twitter.searchTwitter()
# Format the current datetime in a filename-friendly format
timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
filename = f"{query}_{timestamp}.json"
with open(filename, 'w', encoding='utf-8') as file:
# Assuming `data` is a JSON string; if `data` is a dictionary, use json.dump(data, file)
file.write(data)
else:
print(login["status"])