-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpage_clipper.py
More file actions
74 lines (59 loc) · 1.73 KB
/
webpage_clipper.py
File metadata and controls
74 lines (59 loc) · 1.73 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
65
66
67
68
69
70
71
72
73
74
import json
import os
import scripts.webPagePicChecker as gS
import matplotlib.pyplot as plt
# Default pic save location
picDir = os.path.join(os.getcwd(),'temp','temp.png')
# JSON FILE TO LOAD
filename = 'websites.json'
file_object = open(filename, 'r')
data = json.load(file_object)
file_object.close()
# Extract stuff
name = data['name']
url = data['url']
area = data['checkArea']
# Temp container
temp_area = {}
# Key-Press Event
def on_press(event):
# only do something if "e" is pressed
if event.key != 'e':
return
# Get axes limits
xlim = ax.get_xlim()
ylim = ax.get_ylim()
# Save Image size
temp_area['x'] = xlim[0]
temp_area['y'] = ylim[1]
temp_area['width'] = xlim[1] - xlim[0]
temp_area['height'] = ylim[0] - ylim[1]
# Close the figure and to next one
plt.close()
# Iterate over all websites to check
for i,n in enumerate(name):
# Get Browser to website
check = gS.webPagePicChecker(url = url[i], name = name[i])
check.setUpBrowser()
# Get a picture
check.getPicture(picDir)
# Load picture and show it
photo = plt.imread(picDir)
# Generate figure and axes
fig, ax = plt.subplots()
ax.set(title='Resize to observable size and press (e) to exit and save!')
ax.imshow(photo)
fig.canvas.mpl_connect('key_press_event', on_press)
plt.show()
# Save Data
area[i]['x'] = temp_area['x']
area[i]['y'] = temp_area['y']
area[i]['width'] = temp_area['width']
area[i]['height'] = temp_area['height']
# Save data in json
data = {}
data['name'] = name
data['url'] = url
data['checkArea'] = area
with open(filename, 'w') as outfile:
json.dump(data, outfile)