-
Notifications
You must be signed in to change notification settings - Fork 8
/
db.py
50 lines (30 loc) · 1.09 KB
/
db.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
import pymongo
import os
from Links import getLinks
from Article import getArticle
from title import get_title
from image import Getimage
import time
from config import *
myclient = pymongo.MongoClient(CloudUri)
mydb = myclient[DatabaseName]
mycol = mydb[collectionName]
dblist = myclient.list_database_names()
collist = mydb.list_collection_names()
# It Will Insert article after 600ms
while True:
for link in getLinks():
TITLE = str(get_title(link).text)
PARA = getArticle(link)
ArticleUrl = str(link)
IMAGEURL = str(Getimage(link))
FinalArticle = { "title": TITLE, "para": PARA, "image": IMAGEURL ,"articleurl": ArticleUrl}
if mycol.find_one({"title":TITLE}):
print("Article already Exist in Database Skipping it")
else:
try:
mycol.insert_one(FinalArticle)
print(f"Title: {TITLE} Database Inserted")
except Exception as e :
print(e)
time.sleep(600)