-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
82 lines (65 loc) · 1.9 KB
/
test.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# import requests
# import bot
# client = bot.authorization()
# list = [
# "elonmusk",
# "narendramodi",
# "BarackObama",
# "justinbieber",
# "katyperry" ,
# "rihanna",
# "Cristiano",
# "taylorswift13",
# "narendramodi",
# "TheEllenShow"
# ]
# d = {}
# for username in list:
# user = client.get_user(username = username)
# d[user.data.id] = 0
# print(d)
import os
import requests
import json
from dotenv import load_dotenv
load_dotenv()
URL = os.getenv("MONGODB_URL")
HEADERS = {
'Content-Type': 'application/json',
'Access-Control-Request-Headers': '*',
'api-key': os.getenv("MONGODB_API_KEY"),
}
# with open("C:/Users/rebca/Documents/rePro/twitterBot/quotes.json", "r",encoding="utf8") as f:
# # control + arrow key to move a word and delete to delete the right character
# data = json.load(f)
# # print(data)
def write():
"""takes a user:int and tweet_id:int
returns error, 0: success, 1: failure"""
BODY = {
"dataSource": "twitterbot",
"database": "twitterbot",
"collection": "quotes",
"documents": data[40000: ]
# "filter": {
# "_id": {"$oid": os.getenv("MONGODB_ID_OBJECTID")}
# },
# "update": {
# "$set": {
# user: {"$numberLong": str(tweet_id)}
# }
# }
}
r = requests.post(url=URL+"/action/insertMany",
headers=HEADERS, json=BODY)
if r.status_code == 200:
if json.loads(r.text) == None:
raise Exception("Nothing recieved: ", r.text)
else:
if json.loads(r.text)['modifiedCount'] != 0:
return 0
else:
raise Exception("MonogDB update error: ", r.content)
else:
raise Exception(r.status_code, r.text)
# write()