-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-austria.py
72 lines (60 loc) · 2.26 KB
/
main-austria.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
import time
import pandas as pd
from hotel_data import getDataFromHotel
# Create lists to store data for each column
column_a = []
column_b = []
column_c = []
# Open the text file for reading
with open('germany-numbers.txt', 'r', encoding='utf-8') as file:
# Iterate over each line in the file
cnt = 0
for line in file:
# Print the current line to the console
# print(line.strip()) # .strip() removes the newline character at the end
url = 'https://www.tagungshotel.com/home.php?Kundenid=' + line.strip()
cnt += 1
print(cnt)
print(url)
# Wait for 1 second before proceeding to the next line
# time.sleep(1)
hotel_data = getDataFromHotel(url)
# Populate lists with JSON data
for section, section_data in hotel_data.items():
column_a.append(section) # Append section name only once
for key, value in section_data.items():
column_a.append('')
column_b.append(key)
column_c.append(value)
column_a.pop()
column_a.append('')
column_b.append('')
column_c.append('')
# # Open a text file for writing
# with open('txt/output.txt', 'w', encoding='utf-8') as f:
# # Iterate over the columns simultaneously
# for a, b, c in zip(column_a, column_b, column_c):
# # Write the data to the file, separated by tabs or spaces
# f.write(f"{a}\n{b}\n{c}\n") # Use '\t' for tab-separated or ' ' for space-separated
# Create DataFrame
df = pd.DataFrame({
'Column A': column_a,
'Column B': column_b,
'Column C': column_c
})
# Write column_a to a text file
with open('txt/column_a.txt', 'w', encoding='utf-8') as f_a:
for item in column_a:
f_a.write(f"{item}\n")
# Write column_b to a text file
with open('txt/column_b.txt', 'w', encoding='utf-8') as f_b:
for item in column_b:
f_b.write(f"{item}\n")
# Write column_c to a text file
with open('txt/column_c.txt', 'w', encoding='utf-8') as f_c:
for item in column_c:
if isinstance(item, str):
item = item.replace('\n', ' ').replace('\r', ' ').replace('\f', ' ').replace('\v', ' ')
f_c.write(f"{item}\n")
# Write DataFrame to Excel
df.to_excel('germany.xlsx', index=False)