-
Notifications
You must be signed in to change notification settings - Fork 0
/
AuctionFlipperCore.py
116 lines (96 loc) · 3.47 KB
/
AuctionFlipperCore.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import asyncio
import json
import logging
import os
import aiohttp
import orjson
import requests
import schedule
import time
from pymongo import MongoClient
from Handlers import PriceHandler, AuctionHandler, ProgressHandler
from Handlers.AuctionHandler import fetch
# Set up logging
# logging.basicConfig(level=logging.INFO)
# logger = logging.getLogger(__name__)
def UpdateCachedPrices():
# Load the prices JSON from the URL
response = requests.get('https://raw.githubusercontent.com/SkyHelperBot/Prices/main/prices.json')
prices = response.json()
# Check if the file exists
if not os.path.exists('cached/prices.json'):
# If the file doesn't exist, create an empty JSON file
with open('cached/prices.json', 'w') as f:
json.dump({}, f)
# Write the prices JSON to the local file
with open('cached/prices.json', 'w') as f:
# delete everything in old one and substitute with new json
json.dump(prices, f)
def UpdateLowestBin():
# Load the prices JSON from the URL
response = requests.get('https://moulberry.codes/lowestbin.json')
prices = response.json()
# Check if the file exists
if not os.path.exists('cached/lowestbin.json'):
# If the file doesn't exist, create an empty JSON file
with open('cached/lowestbin.json', 'w') as f:
json.dump({}, f)
# Write the prices JSON to the local file
with open('cached/lowestbin.json', 'w') as f:
# delete everything in old one and substitute with new json
json.dump(prices, f)
def UpdateDailySales():
# Load the prices JSON from the URL
response = requests.get('https://moulberry.codes/auction_averages/3day.json')
prices = response.json()
# Check if the file exists
if not os.path.exists('cached/DailySales.json'):
# If the file doesn't exist, create an empty JSON file
with open('cached/DailySales.json', 'w') as f:
json.dump({}, f)
# Write the prices JSON to the local file
with open('cached/DailySales.json', 'w') as f:
# delete everything in old one and substitute with new json
json.dump(prices, f)
async def initial_launch():
print('intital launch, Checking Whole DataBase')
UpdateCachedPrices()
UpdateDailySales()
UpdateLowestBin()
PriceHandler.readprices()
async with aiohttp.ClientSession() as session:
response = await fetch(session, 'https://api.hypixel.net/skyblock/auctions')
data = orjson.loads(response)
total_pages = data['totalPages']
await AuctionHandler.CheckAuctions(total_pages)
# Create a new event loop
loop = asyncio.new_event_loop()
# Set the event loop for the current OS thread
asyncio.set_event_loop(loop)
try:
# Call initial_launch and wait for it to finish
loop.run_until_complete(initial_launch())
finally:
# Close the event loop
loop.close()
print('Initial Launch Finished')
# Keep the script running
while True:
UpdateCachedPrices()
UpdateDailySales()
UpdateLowestBin()
PriceHandler.readprices()
# Create a new event loop
loop = asyncio.new_event_loop()
# Set the event loop for the current OS thread
asyncio.set_event_loop(loop)
try:
# Call CheckAuctions and wait for it to finish
loop.run_until_complete(AuctionHandler.CheckAuctions(2))
finally:
# Close the event loop
loop.close()
print('auctions updated')
AuctionHandler.delete_ended_auctions()
print('auctions deleted')
time.sleep(1)