-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataannotation.py
More file actions
48 lines (46 loc) · 1.29 KB
/
Copy pathdataannotation.py
File metadata and controls
48 lines (46 loc) · 1.29 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
from bs4 import BeautifulSoup as bs
import requests
import sys
def main(url):
if not url:
url = input("url:")
rs = requests.get(url)
if rs.status_code != 200:
return
soup = bs(rs.text, 'html.parser')
co = soup.get_text(separator='\n').strip()
start = False
filtered = ""
for l in co.splitlines():
if start:
filtered += l + "\n"
if l.strip() == "y-coordinate":
start = True
ls = filtered.strip().splitlines()
groups = [ls[i:i+3] for i in range(0, len(ls), 3)]
max_x, max_y = 0, 0
for g in groups:
if len(g) != 3:
continue
ix = int(g[0])
iy = int(g[2])
if ix > max_x:
max_x = ix
if iy > max_y:
max_y = iy
grid = [[" " for _ in range(max_x + 1)] for _ in range(max_y + 1)]
for g in groups:
if len(g) != 3:
continue
x_val = int(g[0])
char = g[1]
y_val = int(g[2])
grid[y_val][x_val] = char
for row in grid:
print("".join(row))
if __name__ == '__main__':
if len(sys.argv) > 1:
url = sys.argv[1]
else:
url = 'https://docs.google.com/document/d/e/2PACX-1vSHesOf9hv2sPOntssYrEdubmMQm8lwjfwv6NPjjmIRYs_FOYXtqrYgjh85jBUebK9swPXh_a5TJ5Kl/pub'
main(url)