-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecipher.py
More file actions
64 lines (44 loc) · 1.57 KB
/
Copy pathdecipher.py
File metadata and controls
64 lines (44 loc) · 1.57 KB
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
import requests
from bs4 import BeautifulSoup
url = input("Enter URL: ")
print("Should be a URL with 3 rows, x-axis, character, and y-axis")
def fetch_and_plot_from_pub_url(url):
print("Fetching data from Google Doc...")
response = requests.get(url)
if response.status_code != 200:
print(f"Failed to fetch document. Status code: {response.status_code}")
return
soup = BeautifulSoup(response.text, 'html.parser')
table = soup.find('table')
if not table:
print("No table found in the document.")
return
parsed_data = []
rows = table.find_all('tr')[1:]
for row in rows:
cols = row.find_all('td')
if len(cols) >= 3:
try:
x_str = cols[0].get_text(strip=True)
char = cols[1].get_text(strip=True)
y_str = cols[2].get_text(strip=True)
x = int(x_str)
y = int(y_str)
if not char:
char = ' '
parsed_data.append((x, char, y))
except ValueError:
continue
if not parsed_data:
print("No valid coordinate data found in the table.")
return
max_x = max(item[0] for item in parsed_data)
max_y = max(item[2] for item in parsed_data)
grid = [[' ' for _ in range(max_x + 1)] for _ in range(max_y + 1)]
for x, char, y in parsed_data:
grid[y][x] = char
print("\n--- PLOTTED OUTPUT ---\n")
for y in range(max_y, -1, -1):
print("".join(grid[y]))
doc_url = url
fetch_and_plot_from_pub_url(doc_url)