Skip to content

Commit 37dbd9a

Browse files
Updated data format
+ Added new data saving method
1 parent 90b8d8d commit 37dbd9a

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

main.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import time
66
import click
77
import os
8+
import pprint as pp
89

910
def get_parsed_page(url):
1011
headers = {
@@ -33,6 +34,10 @@ def _get_skin_wears(self, skin_page_url):
3334
page_content = page.find_all("div", {"class": "marker-value cursor-default"})
3435
min_wear = page_content[0].text
3536
max_wear = page_content[1].text
37+
wear_img = []
38+
for url in page.find_all("a"):
39+
if url.get('data-hoverimg') != None:
40+
wear_img.append(url.get('data-hoverimg'))
3641
# Define possible wears
3742
if float(min_wear) < 0.07 and float(max_wear) > 0.00:
3843
possible_wears.append("fn")
@@ -44,6 +49,8 @@ def _get_skin_wears(self, skin_page_url):
4449
possible_wears.append("ww")
4550
if float(min_wear) < 1 and float(max_wear) > 0.45:
4651
possible_wears.append("bs")
52+
# Zip lists
53+
possible_wears = dict(zip(possible_wears, wear_img))
4754
# Return
4855
return possible_wears
4956

@@ -76,15 +83,17 @@ def _get_case_contents(self, case_page_url):
7683
possible_wears = self._get_skin_wears(skin_url)
7784
# Description & Lore
7885
description,lore = self._get_skin_description_and_lore(skin_url)
79-
# Add
86+
# Full Skin details
87+
skin_details = {title : [{"url" : skin_url}, {"image" : image_url}, {"possible_wears" : possible_wears}, {"desc" : description}, {"lore" : lore}]}
88+
# Add to case_content
8089
if rarity == 'Covert':
81-
case_content['Covert Skins'] += [{"title" : title}, {"image" : image_url}, {"possible_wears" : possible_wears}, {"desc" : description}, {"lore" : lore}]
90+
case_content['Covert Skins'].append(skin_details)
8291
elif rarity == 'Classified':
83-
case_content['Classified Skins'] += [{"title" : title}, {"image" : image_url}, {"possible_wears" : possible_wears}, {"desc" : description}, {"lore" : lore}]
92+
case_content['Classified Skins'].append(skin_details)
8493
elif rarity == 'Restricted':
85-
case_content['Restricted Skins'] += [{"title" : title}, {"image" : image_url}, {"possible_wears" : possible_wears}, {"desc" : description}, {"lore" : lore}]
94+
case_content['Restricted Skins'].append(skin_details)
8695
elif rarity == 'Mil-Spec':
87-
case_content['Mil-Spec Skins'] += [{"title" : title}, {"image" : image_url}, {"possible_wears" : possible_wears}, {"desc" : description}, {"lore" : lore}]
96+
case_content['Mil-Spec Skins'].append(skin_details)
8897
return case_content
8998

9099
def _get_all_cases(self):
@@ -117,14 +126,15 @@ def get_case_skins(self):
117126

118127

119128
@click.command()
120-
@click.option('--method', default=1, type=click.IntRange(1,2), help="Sets the data saving method")
129+
@click.option('--method', default=1, type=click.IntRange(1,3), help="Sets the data saving method")
121130
@click.option('--indent', default=2, help="Sets the JSON indentation level")
122131
def dump_data(method, indent):
123132
"""supr3me's csgostash-scraper
124133
Command-line syntax: python3 main.py --method 1 --indent 2
125134
Available methods:
126135
1 - Save in a single file
127136
2 - Save in separate files
137+
3 - Save in single & separate files
128138
"""
129139
# Preload data
130140
print('This process can take a while, please be patient..')
@@ -149,6 +159,16 @@ def dump_data(method, indent):
149159
json.dump(data_to_dump[case], fp, indent=indent)
150160
print(f"Creating 'data\{filename}.json'")
151161
print("Finished!")
162+
elif method == 3: # Dump into single and separate case files
163+
with open('output.json', 'w') as fp:
164+
json.dump(data_to_dump, fp, indent=indent)
165+
print(f"Creating 'data\output.json'")
166+
for case in data_to_dump:
167+
filename = str(case).lower().replace(" ","_")
168+
with open(f'{filename}.json', 'w') as fp:
169+
json.dump(data_to_dump[case], fp, indent=indent)
170+
print(f"Creating 'data\{filename}.json'")
171+
print("Finished!")
152172

153173
if __name__ == '__main__':
154174
dump_data()

0 commit comments

Comments
 (0)