-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
108 lines (80 loc) · 2.95 KB
/
app.py
File metadata and controls
108 lines (80 loc) · 2.95 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
from flask import Flask, render_template, request, send_file
from werkzeug.utils import secure_filename
import os
import DarkModePdf
from PyPDF3 import PdfFileMerger
import shutil
import git
app = Flask(__name__)
uploadsPath = '/home/thechawla225/mysite/uploads/'
app.config['UPLOAD_FOLDER'] = uploadsPath
BASE_DIR = '/home/thechawla225/mysite/'
@app.route('/')
def hello_world():
return render_template('index.html')
@app.route('/uploader', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
f = request.files['file']
# Save File
f.save(os.path.join(
app.config['UPLOAD_FOLDER'], secure_filename(f.filename)))
# PDF to images
DarkModePdf.pdf_to_images(f.filename, uploadsPath, uploadsPath)
# Merge Images to pdf
num_pages = DarkModePdf.image_to_pdf(
f.filename, uploadsPath, uploadsPath)
# merge pdfs:
merger = PdfFileMerger()
for i in range(num_pages):
name = uploadsPath + "temp" + str(i) + ".pdf"
with open(name, "rb") as file:
merger.append(file)
merger.write(BASE_DIR + 'DarkFile.pdf')
merger.close()
path_to_file = os.path.join(BASE_DIR, 'DarkFile.pdf')
shutil.rmtree(uploadsPath)
if not os.path.exists(uploadsPath):
os.makedirs(uploadsPath)
return send_file(path_to_file)
@app.route('/uploaderMobile', methods=['GET', 'POST'])
def upload_file_mobile():
if request.method == 'POST':
f = request.files['file']
# Save File
f.save(os.path.join(
app.config['UPLOAD_FOLDER'], secure_filename(f.filename)))
# PDF to images
DarkModePdf.pdf_to_images(f.filename, uploadsPath, uploadsPath)
# Merge Images to pdf
num_pages = DarkModePdf.image_to_pdf(
f.filename, uploadsPath, uploadsPath)
# merge pdfs:
merger = PdfFileMerger()
for i in range(num_pages):
name = uploadsPath + "temp" + str(i) + ".pdf"
with open(name, "rb") as file:
merger.append(file)
merger.write(BASE_DIR + 'DarkFile.pdf')
merger.close()
return 0
@app.route('/receiveMobile', methods=['GET', 'POST'])
def sendFileMobile():
path_to_file = os.path.join(BASE_DIR, 'DarkFile.pdf')
shutil.rmtree(uploadsPath)
if not os.path.exists(uploadsPath):
os.makedirs(uploadsPath)
return send_file(path_to_file)
@app.route('/sendApk', methods=['GET', 'POST'])
def send_Apk():
path_to_file = os.path.join(BASE_DIR, 'templates/NiteMode.apk')
return send_file(path_to_file)
@app.route('/update_server', methods=['POST'])
def webhook():
if request.method == 'POST':
git.cmd.Git().pull('https://github.com/thechawla225/NiteModeFlask', 'main')
return 'Updated PythonAnywhere successfully', 200
else:
return 'Wrong event type', 400
if __name__ == '__main__':
app.run(debug=True)