-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdayone.py
109 lines (88 loc) · 3.19 KB
/
dayone.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
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
#!/usr/bin/env python
# coding: utf-8
# In[6]:
from flask import Flask, render_template, request, send_file
from flask import redirect
from werkzeug.utils import secure_filename
import sys
import json
import io
import getMagnet
app = Flask(__name__)
# In[7]:
@app.route('/upload')
def render_file():
return render_template('upload.html')
# In[ ]:
# In[8]:
def makeFile(openName, calendar):
if openName.split('.')[1] != 'json': # not json file
return 'NoJson'
with open(openName, encoding='UTF8') as st_json:
st_python = json.load(st_json)
if not 'entries' in st_python:
return 'NoDayto'
obj = st_python.get('entries')
obj.reverse()
# filename = '2020-01'
#f = open(self._filename + '.txt', 'w')
# f = io.open(self._filename + '.txt', 'w', newline='')
f = io.open('Journal-'+ calendar + '.txt', 'w', encoding = 'utf8',newline='')
for journal in obj:
Date = str(journal['creationDate'])
seoulTime = int(str(journal['creationDate'])[11:13]) + 9
if seoulTime >= 24:
seoulTime -= 24
changeDate = int(journal['creationDate'][8:10]) + 1
if changeDate < 10:
changeDate = '0' + str(changeDate)
else:
changeDate = str(changeDate)
else:
changeDate = journal['creationDate'][8:10]
if seoulTime < 10:
seoulTime = '0' + str(seoulTime)
Date = Date[:8] + str(changeDate) + ' ' + str(seoulTime) + Date[13:19]
Date = '### ' + Date + '\n'
if calendar == Date[4:11]:
Text = journal['text']
removeImage = Text.split('\n\n')
tt = removeImage[0] + '\n'
# print(tt)
latitude = str(journal['location']['latitude'])
longitude = ',%20' + str(journal['location']['longitude']) + '\n\n'
googleUrl = 'https://maps.google.com/?q=' + latitude + longitude
# print(googleUrl)
Data = Date + tt + googleUrl
# print(Data)
f.write(Data)
f.close()
return 'success'
@app.route('/fileUpload', methods=['GET','POST'])
def upload_file():
if request.method == 'POST':
f = request.files['file']
calendar = request.form['calendar']
f.save(secure_filename(f.filename))
ret = makeFile(f.filename, calendar)
if ret == 'NoJson':
return 'Failed : Not Json File'
elif ret == 'NoDayto':
return 'Failed : Not dayone Json File'
else:
return send_file('/Journal-'+ calendar+ '.txt', mimetype=None, attachment_filename=calendar+ '.txt',# 다운받아지는 파일 이름.
as_attachment=True)
#return 'success'
@app.route('/test/<userName>', methods=['GET','POST'])
def test(userName):
if request.method == 'GET':
return 'success ' + userName
# In[9]:
@app.route('/torrentSaturday')
def gettorrentSaturday():
# return 'http://www.naver.com'
# return redirect("http://www.example.com", code=302)
return redirect(getMagnet.getSaturdaySong(), code=302)
if __name__ == '__main__':
app.run(host='192.168.1.81', port='5000', debug = True)
# app.run()