-
Notifications
You must be signed in to change notification settings - Fork 0
/
BOM.py
62 lines (44 loc) · 1.33 KB
/
BOM.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
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 4 12:32:51 2022
@author: victo
"""
import time
import requests
import pandas as pd
import json
def get_data():
status = 1
sec = 0.2
while status == 1:
x = requests.get("http://160.85.252.148")
time.sleep(sec)
sec += 0.2
if x.status_code != 500:
status += 1
print(x.text)
return x.text
def clean_data():
data = json.loads(get_data())
df = pd.DataFrame(list(data.items()), columns = ['Item','Price'])
clean = df[df['Price'].apply(lambda x: str(x).isdigit())]
clean = clean.reset_index(drop = True)
#print(len(clean['Item']))
final = corrector(clean)
print(final)
print('Total: ',final.sum(numeric_only = True))
return final
def corrector(clean):
old_values = []
new_values = []
i = 1
for i in range(len(clean['Item'])):
old_values.append(clean['Item'][i])
#print(old_values)
i =+ 1
for items in range(len(old_values)):
new_values.append(old_values[items].encode("windows-1252").decode("utf-8"))
items =+ 1
#print(new_values)
return clean.replace(old_values, new_values )
data = clean_data()