-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathbuff_scanner.py
74 lines (57 loc) · 2.31 KB
/
buff_scanner.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
import argparse
import codecs
import csv
import datetime
import json
import asyncio
from buff2steam.provider.buff import Buff
header = [
'market_hash_name', 'buff_says_ratio', 'buff_sell_num', 'buff_min_price', 'buff_says_steam_price',
'buff_market_url', 'steam_market_url'
]
async def main():
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--config', help='config path', default='./config.json')
args = parser.parse_args()
with open(args.config) as fp:
config = json.load(fp)
filename = 'buff_scanner_result_' + str(datetime.datetime.now().strftime('%Y%m%d%H%M%S')) + '.csv'
with open(filename, 'wb') as fp:
fp.write(codecs.BOM_UTF8)
with open(filename, 'a', newline='') as fp:
csv.writer(fp).writerow(header)
buff = Buff(
config['main']['game'],
config['main']['game_appid'],
config['buff']
)
total_page = await buff.get_total_page()
visited = set()
for each_page in range(1, total_page + 1):
try:
items = await buff.get_items(each_page)
except ValueError:
continue
for item in items:
if item['id'] in visited:
continue
market_hash_name = item['market_hash_name']
buff_sell_num = item['sell_num']
steam_market_url = item['steam_market_url']
buff_min_price = int(float(item['sell_min_price']) * 100)
buff_says_steam_price = int(float(item['goods_info']['steam_price_cny']) * 100)
if not config['main']['max_price'] > buff_min_price > config['main']['min_price']:
continue
buff_says_ratio = round(buff_min_price / buff_says_steam_price if buff_says_steam_price else 1, 4)
if buff_says_ratio > config['main']['accept_buff_threshold']:
continue
with open(filename, 'a', newline='', encoding='utf-8') as fp:
row = [
market_hash_name, buff_says_ratio, buff_sell_num,
buff_min_price / 100, buff_says_steam_price / 100,
'https://buff.163.com/market/goods?goods_id=' + str(item['id']), steam_market_url
]
print(row)
csv.writer(fp).writerow(row)
if __name__ == '__main__':
asyncio.run(main())