-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOutput Screenshots.py
70 lines (52 loc) · 1.94 KB
/
Output Screenshots.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
import urllib
import requests
import os
splitter = "#Take Screenshot"
print("""
This Script will automatically take screenshots of your Code Outputs
You can also divide your File into multiple parts and take Screenshots of Individual Parts by adding the Comment (#Take Screenshot) to indicate new separation
For more help on this, check out README.md at https://github.com/Divyesh06/Output-Screenshots
"""
)
python_file = input('Enter the location of your Python File: ')
_input = input
_print = print
output_string = ""
def url_encode(string):
a = urllib.parse.quote(string)
a = a.replace("%0A", "%250A")
return a
def input(prompt):
value = _input(prompt)
full_prompt = prompt+value
global output_string
output_string += full_prompt+'\n'
return value
def print(*args, sep=" ", end="\n"):
global output_string
args = (str(arg) for arg in args)
statement = str(sep).join(args)+str(end)
output_string += statement
_print(statement)
with open(python_file) as f:
content = f.read()
_print(f"""
=====================================
Running {python_file} Now
=====================================
""")
code_blocks = content.split(splitter)
for index, i in enumerate(code_blocks):
exec(i, globals(), locals())
output_string = output_string.strip()
result = requests.get(
f'https://carbonnowsh.herokuapp.com/?code={url_encode(output_string)}&windowTheme=boxy&paddingHorizontal=0px&paddingVertical=0px&backgroundColor={url_encode("#151718")}&exportSize=4x&windowControls=false')
file_name = f'Screenshot{index+1}.png'
with open(file_name, 'wb') as f:
f.write(result.content)
output_string = ""
_print(f"Screenshot saved at ", os.path.join(os.getcwd(), file_name))
_print(f"""
Completed Running {python_file}
If this script helped you save some time, don't forget to Star it on Github
""")