Skip to content

Commit 8262d11

Browse files
author
Jack Li
committed
fetch scraping jobs from db during startup and fix startup error
1 parent 8cad815 commit 8262d11

File tree

13 files changed

+48
-26
lines changed

13 files changed

+48
-26
lines changed

startupApp/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
default_app_config = 'startupApp.apps.MyAppConfig'

startupApp/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from django.apps import AppConfig
2-
from utils import get_db_handle
32
from ticketscraping.scraping import start
43
from datetime import datetime
54

5+
66
class MyAppConfig(AppConfig):
7-
name = "tmtracker"
7+
name = "startupApp"
88
verbose_name = "start tmtracker"
9-
9+
1010
def ready(self):
11-
print(f"server started at {datetime.now().strftime('%d/%m/%Y %H:%M:%S')}")
11+
print(
12+
f"server started at {datetime.now().strftime('%d/%m/%Y %H:%M:%S')}")
1213
print("=== database connection is established ===")
1314
start()

startupApp/migrations/__init__.py

Whitespace-only changes.

startupApp/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.

startupApp/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

startupApp/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.shortcuts import render
2+
3+
# Create your views here.

storage/base.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
from pymongo import collection
22

3-
def __insert_one__(coll: collection.Collection, doc: dict):
3+
def insert_one__(coll: collection.Collection, doc: dict):
44
return coll.insert_one(doc)
55

6-
def __insert_many__(coll: collection.Collection, docs: list):
6+
def insert_many__(coll: collection.Collection, docs: list):
77
return coll.insert_many(docs)
88

9-
def __delete_one__(coll: collection.Collection, filter: dict):
9+
def delete_one__(coll: collection.Collection, filter: dict):
1010
return coll.delete_one(filter)
1111

12-
def __delete_many__(coll: collection.Collection, filter: dict):
12+
def delete_many__(coll: collection.Collection, filter: dict):
1313
return coll.delete_many(filter)
1414

15-
def __find_one_and_replace__(coll: collection.Collection, filter: dict, new_doc: dict):
15+
def find_one_and_replace__(coll: collection.Collection, filter: dict, new_doc: dict):
1616
return coll.find_one_and_replace(filter, new_doc)
1717

18-
def __find_one_and_delete__(coll: collection.Collection, filter: dict):
18+
def find_one_and_delete__(coll: collection.Collection, filter: dict):
1919
return coll.find_one_and_delete(filter)
2020

21-
def __find_one__(coll: collection.Collection, filter: dict, projection):
21+
def find_one__(coll: collection.Collection, filter: dict, projection):
2222
return coll.find_one(filter=filter, projection=projection)
2323

24-
def __find_many__(coll: collection.Collection, filter: dict, projection, **kwargs):
24+
def find_many__(coll: collection.Collection, filter: dict, projection, **kwargs):
2525
return coll.find(filter=filter, projection=projection, **kwargs)

storage/storage.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ..utils import get_db_handle
1+
from utils import get_db_handle
22
from .base import *
33
from uuid import uuid4
44

@@ -7,48 +7,48 @@ def insert_one(collection_name, doc: dict, db_name="tickets"):
77
db = get_db_handle(db_name)
88
doc["_id"] = str(uuid4())
99
coll = db[collection_name]
10-
return __insert_one__(coll, doc)
10+
return insert_one__(coll, doc)
1111

1212
# insert many
1313
def insert_many(collection_name, docs: list, db_name="tickets"):
1414
db = get_db_handle(db_name)
1515
for doc in docs:
1616
doc["_id"] = str(uuid4())
1717
coll = db[collection_name]
18-
return __insert_many__(coll, docs)
18+
return insert_many__(coll, docs)
1919

2020
# delete one
2121
def delete_one(collection_name, filter: dict, db_name="tickets"):
2222
db = get_db_handle(db_name)
2323
coll = db[collection_name]
24-
return __delete_one__(coll, filter)
24+
return delete_one__(coll, filter)
2525

2626
# delete many
2727
def delete_many(collection_name, filter: dict, db_name="tickets"):
2828
db = get_db_handle(db_name)
2929
coll = db[collection_name]
30-
return __delete_many__(coll, filter)
30+
return delete_many__(coll, filter)
3131

3232
# find one and replace
3333
def find_one_and_replace(collection_name, filter: dict, new_doc: dict, db_name="tickets"):
3434
db = get_db_handle(db_name)
3535
coll = db[collection_name]
36-
return __find_one_and_replace__(coll, filter, new_doc)
36+
return find_one_and_replace__(coll, filter, new_doc)
3737

3838
# find one and delete
3939
def find_one_and_delete(collection_name, filter: dict, db_name="tickets"):
4040
db = get_db_handle(db_name)
4141
coll = db[collection_name]
42-
return __find_one_and_delete__(coll, filter)
42+
return find_one_and_delete__(coll, filter)
4343

4444
# find one
4545
def find_one(collection_name, filter: dict, projection=None, db_name="tickets"):
4646
db = get_db_handle(db_name)
4747
coll = db[collection_name]
48-
return __find_one__(coll, filter, projection)
48+
return find_one__(coll, filter, projection)
4949

5050
# find many
5151
def find_many(collection_name, filter: dict, projection=None, db_name="tickets", **kwargs):
5252
db = get_db_handle(db_name)
5353
coll = db[collection_name]
54-
return __find_many__(coll, filter, projection, **kwargs)
54+
return list(find_many__(coll, filter, projection, **kwargs))

ticketscraping/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ def get_top_picks_url(
1111
EVENT_ID = "0C005B5587A017CF"
1212
BASIC_REQ_HEADER = {"origin": "https://www.ticketmaster.com",
1313
"referer": "https://www.ticketmaster.com/"}
14+
DATABASE = {
15+
"EVENTS": "events",
16+
"TOP_PICKS": "top-picks"
17+
}
1418
def get_top_picks_header(): return {
1519
**BASIC_REQ_HEADER,
1620
"tmps-correlation-id": str(uuid4())

0 commit comments

Comments
 (0)