This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
187 lines (143 loc) · 4.77 KB
/
main.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
#flash framework - which is micro framework
from flask import Flask
from flask import request
import requests
from flask import render_template ,redirect ,url_for ,jsonify ,make_response
# from flask import render_template ,redirect ,url_for ,jsonify
import os
from EmailSend import email , send
#from time import sleep
# gives covid data
from CoronaDataNew import done , retry
#from datetime import datetime
# database lib
from dbinfo import databaseCloudantExatract , databaseCloudantAdd
"""
# database lib
from cloudant import Cloudant
from cloudant.result import Result
"""
# for multi processing
# from multiprocessing import Process
# list name
# data = []
# maildata = set()
# ---------------------------------------------------------------
# parameters for cloudant database
'''
api = "mtFmNq2TppQsnUV2o8OQqcYEbt1cNnKmUWacbJ9AGK_E"
url_link = "https://b9932f06-c0c7-4666-a9bf-72877bb23d13-bluemix.cloudantnosqldb.appdomain.cloud"
# connect
client = Cloudant.iam(None , api , url = url_link , connect=True)
# Access a database
print("Accessing the data . . .")
db = client['info']
res = Result(db.all_docs, include_docs=True)
for x in res:
maildata.add(x['doc']['email'])
print("__Done__")
link = None
link4 = None
link5 = None
'''
# ---------------------------------------------------------------
# Exract Information From Database
maildata = databaseCloudantExatract()
# --------------------------------------------------------------
app = Flask(__name__, static_url_path='')
port = int(os.getenv('PORT', 8000))
@app.route('/', methods = ['GET','POST'])
def index():
return redirect('main')
#return app.send_static_file("index.html")
@app.route('/main', methods = ['GET','POST'])
def homepage():
if request.method == 'POST':
# print('done')
if 'name' in request.form and 'email' in request.form:
name = request.form['name']
mail = request.form['email']
if mail in maildata: return "<script>window.alert('E-Mail is Already Registered'); window.location.href = '/main';</script>"
# detial = { 'name': name , "email" : mail}
# doc = db.create_document(detial)
# Use databaseCloudantAdd() - fun to add data in database
databaseCloudantAdd(name , mail)
maildata.add(mail)
email(name,mail)
return "<script>window.alert('Successfully Registered'); window.location.href = '/main';</script>"
# return app.send_static_file("index.html")
# else:
# print("")
return render_template("index.html")
@app.route('/privacy-policy')
def privacy():
return render_template("privacy.html")
@app.route('/terms-condition')
def terms():
return render_template("term.html")
'''
@app.route('/data/')
def dataAll():
return jsonify(data)
@app.errorhandler(500)
def page_not_found(e):
return render_template('500.html'), 404
'''
# inbuilt function which takes error as parameter
@app.errorhandler(404)
def notfound(e):
return app.send_static_file("error.html")
@app.errorhandler(500)
def notfound(e):
return app.send_static_file("error.html")
@app.route('/api/go/')
def add():
retry()
l = done()
for x in maildata:
send(l , x)
print("done")
#maildata.clear()
return "<script>window.alert('Done Sir'); window.location.href = '/main';</script>"
@app.route("/sitemap.xml")
def sitemap_xml():
response= make_response(render_template("sitemap.xml"))
response.headers['Content-Type'] = 'application/xml'
return response
@app.route("/main/sitemap.xml")
def sitemapsite():
resp= make_response(render_template("site.xml"))
resp.headers['Content-Type'] = 'application/xml'
return resp
@app.route("/robots.txt")
def robots_txt():
return render_template("robots.txt")
'''
@app.route('/api/rm/<string:n>/')
def remove(n):
maildata.remove(n)
return "<script>window.alert('Succesfully UnSubscribed'); window.location.href = '/';</script>"
@app.route('/api/del/')
def dell():
data.clear()
maildata.clear()
return "<script>window.alert('All Data Clear'); window.location.href = '/';</script>"
'''
'''
@app.route('/senddata', methods=['POST'])
def testfn():
if request.method == 'POST':
#print() # parse as JSON
val = None
val = request.get_json()
global link , link4, link5
link4 = val['link4']
link5 = val['link5']
link = None
link = [link4 , link5]
return 'Sucesss', 200
'''
if __name__ == '__main__':
# host='0.0.0.0',
app.run(host='0.0.0.0',port=port ,debug = True , use_reloader=False)
# release the data