-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyFyle.py
More file actions
149 lines (124 loc) · 3.83 KB
/
PyFyle.py
File metadata and controls
149 lines (124 loc) · 3.83 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import os, time, docx, json
import pyautogui as pyg
from PIL import ImageGrab
from docx.shared import Inches,Pt,Mm
from docx.enum.style import WD_STYLE_TYPE
from docx.enum.text import WD_TAB_ALIGNMENT
def genscreen(filename = "Script.py", path = os.getcwd(), ss = "ScreenShot.png"):
#Run CMD
pyg.keyDown('win')
pyg.press('r')
pyg.keyUp('win')
time.sleep(0.5)
print(".", end = '')
pyg.typewrite('cmd')
pyg.press('enter')
time.sleep(0.5)
print(".", end = '')
#Change Directory
pyg.typewrite(path[:2])
pyg.press('enter')
time.sleep(0.5)
pyg.typewrite('cd ' + path)
pyg.press('enter')
time.sleep(0.5)
print(".", end = '')
#Prepping The Screen
pyg.typewrite('echo off')
pyg.press('enter')
time.sleep(0.5)
pyg.typewrite('cls')
pyg.press('enter')
time.sleep(0.5)
print(".", end = '')
#Execute Python Script
pyg.typewrite('python ' + filename)
pyg.press('enter')
time.sleep(1)
print(".", end = '')
#Take Screenshot
pyg.keyDown('alt')
pyg.press('prtscr')
pyg.keyUp('alt')
time.sleep(1)
print(".", end = '')
# Grab Image From Clipboard And Save As .png
im = ImageGrab.grabclipboard()
im.save("out\\" + ss, 'PNG')
time.sleep(1)
print(".", end = '')
# Exit
pyg.typewrite('exit')
pyg.press('enter')
time.sleep(0.5)
print(".", end = '')
return ss
# Read detail.json Into detail
with open("detail.json", "r") as read_file:
detail = json.load(read_file)
# Initializing Required Data Elements
UID = detail['user']['uid'] #input("UID - ")
githandle = detail['user']['githandle'] #input("githandle - ")
source = detail['infile'] #"Script.py"
aim = "WAP to calculate area of a circle" #input("Aim : ")
print("Preparing")
time.sleep(0.5)
# Create Directory To Output Generated Files
if not os.path.exists('out') :
os.mkdir('out')
print(".", end = '')
# Read Code
code = open(source,"r")
print(".", end = '')
# Capture Screenshot
screen = genscreen(source)
print(".", end = '')
doc=docx.Document()
# Set Page Layout
section = doc.sections[0]
section.page_height = Mm(297)
section.page_width = Mm(210)
section.left_margin = Mm(25.4)
section.right_margin = Mm(25.4)
section.top_margin = Mm(25.4)
section.bottom_margin = Mm(25.4)
section.header_distance = Mm(12.5)
section.footer_distance = Mm(12.5)
# Set Page Styles
styles = doc.styles
style = styles.add_style("Head", WD_STYLE_TYPE.PARAGRAPH)
style.base_style = styles["Normal"]
style.font.name = 'Calibri'
tab_stops = style.paragraph_format.tab_stops
tab_stops.add_tab_stop(Inches(3.0), WD_TAB_ALIGNMENT.CENTER)
tab_stops.add_tab_stop(Inches(6.0), WD_TAB_ALIGNMENT.RIGHT)
# Add Header
header = section.header
paragraph = header.paragraphs[0]
paragraph.text = "\t\t" + UID
paragraph.style = doc.styles["Head"]
# Add Footer
footer = section.footer
paragraph = footer.paragraphs[0]
paragraph.text = "\t\t@" + githandle
paragraph.style = doc.styles["Head"]
# Create Styles
for s in detail['styles']:
style = doc.styles.add_style(s, WD_STYLE_TYPE.PARAGRAPH)
style.font.name = detail['styles'][s]['font']
style.font.size = Pt(detail['styles'][s]['size'])
style.font.bold = detail['styles'][s]['bold']
# Add Aim
p = doc.add_paragraph("Aim :", style = 'Heading')
p = doc.add_paragraph(aim, style = 'Text')
# Add Code
p = doc.add_paragraph("Code :", style = 'Heading')
p = doc.add_paragraph("", style = 'Code')
for c in code:
p.add_run(c)
# Attach Screenshot
doc.add_paragraph("Output :", style = 'Heading')
doc.add_picture('out\\' + screen, width = Inches(5.5))
# Save
doc.save('out\\' + detail['outfile'] + '.docx')
print("\nDone !")