This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scalp.py
56 lines (53 loc) · 1.95 KB
/
scalp.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
import os
import redis
import spontit
import requests
from time import time, sleep
from urllib.parse import urlparse
from spontit import SpontitResource
from datetime import datetime, timedelta
url = urlparse(os.environ.get("REDIS_URL"))
red = redis.Redis(host=url.hostname, port=url.port, username=url.username, password=url.password, ssl=True, ssl_cert_reqs=None)
notify = SpontitResource('rtxscalping', os.environ['SPONTIT_KEY'])
def scalp():
try:
r = requests.get(os.environ['POWER_URL'] + str(time()))
r = r.json()
except requests.exceptions.RequestException as e:
print(e)
sys.stdout.flush()
return ""
for prod in r['Products']:
if prod['StockCount'] > 0:
if not red.exists('in_stock', prod['TitleSlug']):
red.lpush('in_stock', prod['TitleSlug'])
msg = """
IN STOCK: {stock_count}
- NAME: {title}
- URL: https://www.power.dk{url}
------------------------------------------------------
""".format(
stock_count = prod['StockCount'],
title = prod['Title'],
url = prod['Url']
)
print(msg)
notify.push(
push_content=prod['Title'],
link="https://www.power.dk{}".format(prod['Url']),
should_open_link_in_app=False,
content=msg)
def cleanup():
try:
r = requests.get(os.environ['POWER_URL'] + str(time()))
r = r.json()
except requests.exceptions.RequestException as e:
print(e)
sys.stdout.flush()
return ""
for prod in r['Products']:
for slug in prod['TitleSlug']:
if red.exists('in_stock', slug):
if prod['StockCount'] == 0:
print("Removing {} from list out of stock.".format(prod['TitleSlug']))
red.lpop('in_stock', slug)