-
Notifications
You must be signed in to change notification settings - Fork 1
/
caly.py
211 lines (160 loc) · 6.07 KB
/
caly.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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#-*- coding: utf-8 -*-
import os
import json
import flask
os.environ["CALY_DB_CONF"] = "./key/conf.json"
import static
import uuid
import requests
from flask import render_template
from googleapiclient import discovery
from oauth2client import client
from manager import db_manager
from manager import network_manager
from datetime import datetime, timedelta
from juggernaut import Juggernaut
import urllib
from common.util import utils
from common import logSet
from common import gAPI
#route 안에 googleAuth파일로 들어가서 클래스인 GoogleAuth를 임포트하겠다.
from route.routes import initRoute
from flask import render_template
from flask import redirect, url_for,session
from caldavclient import CaldavClient
from common import FCM
import logging
import logging.handlers
app = flask.Flask(__name__, static_url_path='')
from common.flaskrun import flaskrun
initRoute(app)
# #-*- coding: utf-8 -*-
import logging
import logging.handlers
## 인스턴스만들기.
# mylogger = logging.getLogger()
# mylogger.setLevel(logging.INFO)
# rotatingHandler = logging.handlers.TimedRotatingFileHandler(filename='log/'+'log_caly.log', when='midnight', interval=1, encoding='utf-8')
# fomatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s')
# rotatingHandler.setFormatter(fomatter)
# mylogger.addHandler(rotatingHandler)
# if debugg
# logSet.init()
# # if production
logging.basicConfig(level=logging.INFO, filename='log/log_caly.log',
format='%(asctime)s %(levelname)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
# from datetime import timedelta,datetime
# start_date = "2017-06-08 23:30:00+09:00"
# start_date = start_date[:start_date.find('+')]
# print(start_date)
# start_date = "1992-05-04"
# start_date = datetime.strptime(start_date, '%Y-%m-%d')
# # start_date = start_date + datetime.timedelta(hours=00,minutes=00)
# start_date = start_date.strftime('%Y-%m-%dT%H:%M:%S')
# print(start_date)
# from reco.reco import Reco
# from reinforce.reinforce import Reinforce
# import extractor.event_extractor
# # extracted_json = extractor.event_extractor.extract_info_from_event('0024337293ce52d7f60a9e0532188b74865c42e8dbec644cfb333cee','선릉 민경이와 데이트','2017-06-13','2017-06-13','누우')
# logging.info("extrcted=>"+str(extracted_json))
# reinforce_json = Reinforce(extracted_json).event_reco_result
# logging.info("reinforce ->"+str(reinforce_json))
# reco = Reco(reinforce_json["event_info_data"])
# logging.info("recos==>"+str(reco.get_reco_list()))
# import logging
# import logging.handlers
# #인스턴스만들기.
# mylogger = logging.getLogger('MyLogger')
# mylogger.setLevel(logging.INFO)
# rotatingHandler = logging.handlers.TimedRotatingFileHandler(filename='log/'+ str(datetime.now())+'_log_caly.log', when='m', interval=3, encoding='utf-8')
# fomatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s')
# rotatingHandler.setFormatter(fomatter)
# mylogger.addHandler(rotatingHandler)
# logging = mylogger
@app.route('/')
def hello_wordl():
return 'hello_world_other'
@app.route('/caldavTest')
def caldavTest():
return 'hi'
def event_stream():
pubsub = redis.pubsub()
pubsub.subscribe('syncAlert')
for message in pubsub.listen():
yield 'data: %s\n\n' % message['data']
def event_fetch_calendar():
pubsub = redis.pubsub()
pubsub.subscribe('fetchCalendar')
for message in pubsub.listen():
yield 'data: %s\n\n' % message['data']
#캘린더 리스트로 이동
@app.route('/calList')
def calList():
return render_template('calList.html');
#동기화 다된것 알리미
@app.route('/stream')
def stream():
return flask.Response(event_stream(),
mimetype="text/event-stream")
@app.route('/fetchCalendar')
def fetchCalendar():
return flask.Response(event_fetch_calendar(),
mimetype="text/event-stream")
@app.route('/testGoogleEvnets')
def testGoogleEvnets():
calendar_id = flask.request.args.get('calendar_id')
sync_token = flask.request.args.get('sync_token')
URL = 'https://www.googleapis.com/calendar/v3/calendars/'+urllib.request.pathname2url(calendar_id)+'/events'
body = {
'syncToken':sync_token
}
# access_token = 'ya29.GlthBLzu4Ont7fCiy9y-tz8bnrfwwbycBB1GfkBBZPw1dAWS5Ng36liEftgaDNgYNFJDHoGRZT-X1Adk75SspXSLpJkusY0zW7P0zVELMB9Ruc4PEBK-W_7SdTO_'
# new_access_token = gAPI.checkValidAccessToken(access_token)
# logging.info('newacces=>'+ str(new_access_token))
headers = {
'content-Type': 'application/json',
'Authorization' : 'Bearer ' + 'ya29.GlthBB5Js8pU404F_eoYnMzP20kDVverxK_L8cGhiDqQId12FvKsavw7iTN3vb-teIZOZu-R1KIn_ZMAwTwg8d_BoXFKAjCikfqAbkbZUcYfAzZP_MgkVvpPWl-u'
}
response = requests.get(URL,params = body,headers = headers)
res = json.loads(response.text)
logging.info('new Res' + str(res))
return 'hi'
#test Moudle
@app.route('/test_fetchFire')
def test_fetchFire():
redis.publish('fetchCalendar', 'fetching!')
return 'good'
@app.route('/stopNoti')
def stopNoti():
channel_id = flask.request.args.get('channel_id')
resource_id = flask.request.args.get('resource_id')
# account_hashkey = flask.request.args.get('account_hashkey')
# ya29.GlsyBLU17MXx5UoOZAsbG3i2XDPSzQTaJKtPvQQ0w55C9EGEWV2Msk9zL45Wmcu5xHCON7fFdKNp6KsxaTUwPR6GVyCfvpEBsvR0bBD-eiyyjpKkIAySurthCXmh
access_token = flask.request.args.get('access_token')
URL = 'https://www.googleapis.com/calendar/v3/channels/stop'
body = {
"id" : channel_id,
"resourceId": resource_id
}
headers = {
'content-Type': 'application/json',
'Authorization' : 'Bearer ' + access_token
}
return requests.post(URL,data = json.dumps(body),headers = headers).text
@app.route('/fireFcm')
def fireFcm():
token = flask.request.args.get('token')
data_message = {
"type" : "noti",
"title" : "공지사항입니다 ",
"body" : "콩! 콩 콩진호가간다!"
}
result = FCM.sendOnlyData(token,data_message)
logging.info(str(result))
return 'FCM.sendOnlyData(token,data_message)'
@app.route("/privacyPolicy", methods = ["GET"])
def page_login_get():
return render_template('privacyPolicy.html')
if __name__ == '__main__':
flaskrun(app)