-
Notifications
You must be signed in to change notification settings - Fork 2
/
requestfrommongo.py
44 lines (34 loc) · 1.15 KB
/
requestfrommongo.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os
from dotenv import load_dotenv
from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi
import json
import time
from collections import Counter
url_array = []
def download_future_events_to_json(output_file):
# Get current Unix timestamp
current_timestamp = int(time.time())
# Connect to MongoDB
load_dotenv()
uri = os.getenv('DATABASE_URI')
client = MongoClient(uri, server_api=ServerApi('1'))
db = client['Instagram']
collection = db["Events"]
future_events = list(collection.find({}))
# Convert ObjectId to string for JSON serialization
for event in future_events:
event['_id'] = str(event['_id'])
event['embedded'] = ""
url_array.append(event['url'])
# Write to JSON file
with open(output_file, 'w') as f:
json.dump(future_events, f, indent=2)
# Close the MongoDB connection
client.close()
return future_events
# Usage
output_file = "public/events.json" # Name of the output JSON file
future_events = download_future_events_to_json(output_file)
url_dict = Counter(url_array)
print({x for x, count in url_dict.items() if count > 1})