forked from jsanyam/My-Duniya
-
Notifications
You must be signed in to change notification settings - Fork 0
/
untitled1.py
776 lines (626 loc) · 25.2 KB
/
untitled1.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
# coding:utf-8
import os
import urllib2
from flask import Flask, jsonify, request, render_template, Session, session
from flask.ext.sqlalchemy import SQLAlchemy
from marshmallow import Schema, fields
from flask import g, flash, redirect, url_for
from flask.ext.login import LoginManager, login_user, logout_user, login_required, current_user
from flask.ext.bcrypt import check_password_hash
from flask.ext.bcrypt import generate_password_hash
# from pip.utils import logging
from oauth import OAuthSignIn
import logging
from flask.ext.login import UserMixin
import feedparser
from urllib2 import urlopen
from bs4 import BeautifulSoup
import sys
#import psycopg2
# from sqlalchemy.exc import IntegrityError
# from psycopg2._psycopg import IntegrityError
from sqlalchemy import ForeignKey
import urllib
import json
import requests
from string import punctuation
from wtforms import StringField, PasswordField
from flask_wtf import Form
from wtforms.validators import DataRequired, Regexp, ValidationError, Email, Length
from search_tag import search_to_json
from twitter import get_keywords_twitter
app = Flask(__name__)
app.logger.addHandler(logging.StreamHandler(sys.stdout))
app.logger.setLevel(logging.ERROR)
app.config['SECRET_KEY'] = 'secret'
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL'] #'sqlite:///esoteric.sqlite' #
app.config['OAUTH_CREDENTIALS'] = {
'facebook': {
'id': '',
'secret': ''
}
}
db = SQLAlchemy(app)
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'
class User(db.Model, UserMixin):
__tablename__ = 'users'
id = db.Column(db.BIGINT, primary_key=True)
username = db.Column(db.String(32))
email = db.Column(db.String(100))
password = db.Column(db.String(100))
general = db.Column(db.Integer, default=1)
class Article(db.Model):
__tablename__ = 'articles'
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.Text(), unique=True, nullable=True)
full_story = db.Column(db.Text(), nullable=True)
image = db.Column(db.Text(), nullable=True)
category = db.Column(db.Text(), nullable=True)
description = db.Column(db.Text(), nullable=True)
pubdate = db.Column(db.Text(), nullable=True)
html = db.Column(db.Text(), nullable=True)
def __unicode__(self):
return self.title
def __repr__(self):
return u"%s" % self.title
class Keyword(db.Model):
__tablename__ = 'keywords'
id = db.Column(db.Integer, primary_key=True)
key_name = db.Column(db.Text(), unique=True, nullable=True)
def __unicode__(self):
return self.key_name
def __repr__(self):
return u"%s" % self.key_name
class UserKeyword(db.Model):
__tablename__ = 'user_key'
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.BIGINT, ForeignKey("users.id"), nullable=False)
key_id = db.Column(db.Integer, ForeignKey("keywords.id"), nullable=False)
priority = db.Column(db.Float, nullable=False)
def __unicode__(self):
return self.priority
def __repr__(self):
return u"%f" % self.priority
class NewsKeyword(db.Model):
__tablename__ = 'news_key'
id = db.Column(db.Integer, primary_key=True)
news_id = db.Column(db.Integer, ForeignKey("articles.id"), nullable=False)
key_id = db.Column(db.Integer, ForeignKey("keywords.id"), nullable=False)
def __unicode__(self):
return self.id
def __repr__(self):
return u"%d" % self.id
class Trend(db.Model):
__tablename__ = 'trend'
id = db.Column(db.Integer, primary_key=True)
buzz = db.Column(db.Text(), nullable=True, default=" ")
def __unicode__(self):
return self.json
def __repr__(self):
return self.json
# we use marshmallow Schema to serialize our articles
class ArticleSchema(Schema):
"""
Article dict serializer
"""
url = fields.Method("article_url")
def article_url(self, article):
return article.url()
class Meta:
# which fields should be serialized?
fields = ('id', 'title', 'full_story', 'image', 'category', 'description', 'pubdate', 'html')
article_schema = ArticleSchema()
# many -> allow for object list dump
articles_schema = ArticleSchema(many=True)
# we use marshmallow Schema to serialize our keywords
class KeywordSchema(Schema):
"""
keyword dict serializer
"""
url = fields.Method("keyword_url")
def keyword_url(self, keys):
return keys.url()
class Meta:
# which fields should be serialized?
fields = ('id', 'key_name')
# many -> allow for object list dump
keywords_schema = KeywordSchema(many=True)
def email_exists(form, field):
if User.query.filter_by(email=field.data).count() > 0: #where(User.username == field.data).exists():
raise ValidationError("User with that email already exists")
class RegisterForm(Form):
username = StringField('Username', validators=[DataRequired(), Regexp(r'^[a-zA-Z0-9_]+$',
message = "Username should be one word, letters,"
"numbers and underscores only")])
email = StringField('Email', validators=[DataRequired(), Email(), email_exists])
password = PasswordField('Password', validators=[DataRequired(), Length(min=6)])
class LoginForm(Form):
email = StringField('Email', validators=[DataRequired(), Email()])
password = PasswordField('Password', validators=[DataRequired()])
@login_manager.user_loader
def user_loader(user_id):
user = User.query.filter_by(id=user_id)
if user.count() == 1:
return user.one()
return None
@app.route('/register', methods=('GET', 'POST'))
def register():
form = RegisterForm()
if form.validate_on_submit():
user = User.query.filter_by(username=form.username.data)
if user.count() == 0:
user = User(username=form.username.data, email=form.email.data, password=generate_password_hash(form.password.data))
db.session.add(user)
db.session.commit()
flash('You have registered the email {0}. Please login'.format(form.email.data))
return redirect(url_for('login'))
else:
flash('The username {0} is already in use. Please try a new email.'.format(form.username.data))
return render_template('duniyaregister.html', form=form)
@app.route('/login', methods=("GET", "POST"))
def login():
form = LoginForm()
if form.validate_on_submit():
user = db.session.query(User).filter(User.email==form.email.data, User.general!=0) # User.query.filter_by(email=form.email.data, general=1) #
if user.count() == 0:
flash("You haven't registered with us yet or registered with facebook")
else:
if check_password_hash(user.one().password, form.password.data):
login_user(user.one())
flash("You been logged in", "success")
return redirect(url_for('personal'))
else:
flash("Your email or password doesn't match", "error")
return render_template('duniyalogin.html', form=form)
@app.route('/register_android', methods=('GET', 'POST'))
def register_android():
if request.method == "POST":
user = User.query.filter_by(username=request.form.get('username'))
if user.count() == 0:
user2 = User.query.filter_by(email=request.form.get('email'))
if user2.count() == 0:
user2 = User(username=request.form.get('username'), email=request.form.get('email'), password=generate_password_hash(request.form.get('password')))
db.session.add(user2)
db.session.commit()
return jsonify({'status': 'registered'})
else:
return jsonify({'status': 'This email already exists'})
return jsonify({'status': 'This username already exists'})
@app.route('/login_android', methods=('GET', 'POST'))
def login_android():
if request.method == "POST":
user = db.session.query(User).filter(User.email==request.form.get('email'), User.general!=0) # User.query.filter_by(email=request.form.get('email'), general=1)
if user.count() == 0:
return jsonify({'validation': "You haven't registered with us yet or registered with facebook"})
else:
if check_password_hash(user.one().password, request.form.get('password')):
return jsonify({'validation': "You have successfully logged in"})
else:
return jsonify({'validation': "Your email or password doesn't match"})
@app.route('/logout')
@login_required
def logout():
logout_user()
flash("You've been logged out","success")
return redirect(url_for('news'))
@app.route('/fb_android', methods=['GET', 'POST'])
def fb_android():
if request.method == 'POST':
me = request.get_json(force=True)
user = User.query.filter_by(id=me['id']).first()
if not user:
user = User(id=me['id'], username=me['email'].split('@')[0], email=me['email'], general=0)#, friends=friends) #social_id=social_id,
db.session.add(user)
db.session.commit()
data = ""
for item in me['likes']['data']:
# print item
if 'about' not in item and 'description' not in item:
data = data + item['name'] + " "
elif 'about' not in item:
data = data + item['description'] + " "
elif 'description' not in item:
data = data + item['about'] + " "
else:
data = data + item['description'] + item['about'] + " "
entity_extract(me['id'], data, 0)
return jsonify({'result': 'successful'})
return jsonify({'result': 'success'})
@app.route('/authorize/<provider>')
def oauth_authorize(provider):
if not current_user.is_anonymous:
return redirect(url_for('personal'))
oauth = OAuthSignIn.get_provider(provider)
return oauth.authorize()
@app.route('/callback/<provider>')
def oauth_callback(provider):
if not current_user.is_anonymous:
return redirect(url_for('personal'))
oauth = OAuthSignIn.get_provider(provider)
social_id, username, email, data = oauth.callback()
if social_id is None:
flash('Authentication failed.')
return redirect(url_for('news'))
user = User.query.filter_by(id=social_id).first()
if not user:
user = User(id=social_id, username=username, email=email, general=0)#, friends=friends) #social_id=social_id,
db.session.add(user)
db.session.commit()
entity_extract(social_id, data, 0)
login_user(user, True)
return redirect(url_for('personal'))
# change this
@app.route('/')
def index():
if current_user.is_authenticated:
return redirect(url_for('personal'))
else:
return redirect(url_for('news'))
# return redirect(url_for('register'))
@app.route("/personal")
def personal():
if current_user.is_authenticated and (current_user.general == 0 or current_user.general == 2):
return render_template("personal.html")
else:
return render_template("preferencetry.html") # pref.html
@app.route('/contact')
def contacts():
if current_user.is_authenticated:
return render_template("duniyacontactout.html")
else:
return render_template("duniyacontact.html")
@app.route("/news", methods=["GET"])
def news():
if current_user.is_authenticated:
return render_template("duniyaout.html")
else:
return render_template("duniya.html")
# template opening on clicking tiles
@app.route("/tagnews/<category>")
def tag(category):
if current_user.is_authenticated:
return render_template("lifestyleout.html")
else:
return render_template("lifestyle.html")
@app.route("/tags")
def tags():
if current_user.is_authenticated:
return render_template("usertagout.html")
else:
return render_template("usertag.html")
#sentiment analysis returns json
@app.route("/senti/<category>")
def senti(category):
new_url='http://prractice.herokuapp.com/' + category
g=requests.get(new_url)
data = g.json()
array = {}
#lst = []
i = -1
for item in data['tag']:
i += 1
string = item['full_story']
string = string.lower()
for p in list(punctuation):
string = string.replace(p,'')
string.encode('utf-8')
string = string.encode('ascii', 'ignore')
data = urllib.urlencode({"text":string})
u = urllib.urlopen("http://text-processing.com/api/sentiment/", data)
the_page = u.read()
j=json.loads(the_page)
negative = j['probability']['neg']
positive = j['probability']['pos']
neutral = j['probability']['neutral']
if negative > neutral:
if negative > positive:
print 'negative'
array[i] = 'negative'
else:
print 'positive'
array[i] = 'positive'
else:
if negative > positive:
if negative > 0.5:
print 'negative'
array[i] = 'negative'
else:
print 'neutral'
array[i] = 'neutral'
else:
if positive > neutral:
print 'positive'
array[i] = 'positive'
else:
if positive > 0.5:
print 'positive'
array[i] = 'positive'
else:
print 'neutral'
array[i] = 'neutral'
return jsonify({'sentiment': array})
# REST implementing to return whole news or id wise news in json
@app.route("/news.json/", methods=["GET", "POST"])
@app.route("/news.json/<article_id>", methods=["GET"])
def articles(article_id=None):
if request.method == "GET":
if article_id:
article = Article.query.get(article_id)
if article is None:
return jsonify({"msgs": ["the article you're looking for could not be found"]}), 404
result = article_schema.dump(article)
return jsonify({'article': result})
else:
queryset = Article.query.order_by(Article.id.desc()).limit(50)
# never return the whole set! As it would be very slow
result = articles_schema.dump(queryset)
# jsonify serializes our dict into a proper flask response
return jsonify({"articles": result.data})
# elif request.method == "POST":# and request.is_xhr:
# #val1 = (request.get_json(force=True))
# #val1 = request.args.get('Name', 0, str)
# #return json.dumps({'status': 'OK', 'name': val1, 'desc': val1})
# REST implementation to return news category wise
@app.route('/<category>', methods=["GET"])
def tagger(category):
if request.method == 'GET':
tag = Article.query.filter(Article.category == category).order_by(Article.id.desc()).limit(50)
# print tag.category
if tag is None:
return jsonify({"msgs": ["the tag you're looking for could not be found"]}), 404
result = articles_schema.dump(tag)
return jsonify({'tag': result.data})
# news with id
@app.route('/full_news/<id>')
def full_news(id):
if current_user.is_authenticated:
newsClick(id)
return render_template("fullnewsout.html")
else:
return render_template("fullnews.html")
@app.route('/on_click', methods=['GET', 'POST'])
def on_click():
if request.method == 'POST':
user = User.query.filter_by(email=request.form.get('email')).first()
uid = user.id
nk = NewsKeyword.query.filter_by(news_id=request.form.get('newsid')).all()
for row in nk:
if not db.session.query(UserKeyword).filter(UserKeyword.key_id == row.key_id, UserKeyword.user_id == uid).count():
uk = UserKeyword(key_id=row.key_id, user_id=uid, priority=0.1)
db.session.add(uk)
db.session.commit()
else:
uk = db.session.query(UserKeyword).filter(UserKeyword.key_id == row.key_id, UserKeyword.user_id == uid).first()
uk.priority += 0.1
db.session.commit()
return jsonify({'result': 'success'})
@app.route('/trends/')
def trend_search():
trend = Trend(buzz=" ")
db.session.add(trend)
db.session.commit()
@app.route('/get_tweet')
def trendin():
d={"hello":[1, 2, 3]}
#return json.dumps(d)
return jsonify({'d': d})
@app.route('/get_tweets')
def trending():
trend = Trend.query.filter_by(id=1).first()
d = json.loads(trend.buzz)
return jsonify({'tweets': d})
@app.route('/twitter_handle', methods=['GET', 'POST'])
def twitter_handle():
if request.method == 'POST':
print request.form.get('account')
email = request.form.get('email')
if email:
u = User.query.filter_by(email=email).first()
uid = u.id
else:
uid = current_user.id
keys = get_keywords_twitter(request.form.get('account'))
for key in keys:
if not db.session.query(Keyword).filter(Keyword.key_name == key).count():
keyword = Keyword(key_name=key)
db.session.add(keyword)
db.session.commit()
else:
keyword = Keyword.query.filter_by(key_name=key).first()
if not UserKeyword.query.filter_by(key_id=keyword.id, user_id=uid).count(): #may not be needed
uk = UserKeyword(user_id=uid, key_id=keyword.id, priority=1)
db.session.add(uk)
db.session.commit()
else:
uk = UserKeyword.query.filter_by(key_id=keyword.id, user_id=uid).first()
uk.priority += 1
db.session.commit()
return jsonify({'result': 'updated'})
@app.route('/keywords')
def keywords():
keys = Keyword.query.order_by(Keyword.id).limit(1000)
result = keywords_schema.dump(keys)
return jsonify({'keywords': result.data})
@app.route('/recommended_news', methods=['GET', 'POST'])
def recommended():
if request.method == 'POST':
user = User.query.filter_by(email=request.form.get('email')).first()
id = user.id
else:
id = current_user.id
dict = {}
lists = []
iter = 0
keys = UserKeyword.query.filter_by(user_id=id).order_by(UserKeyword.priority.desc()).limit(50)
for key in keys:
iter += 1
if iter == 1:
nk = NewsKeyword.query.filter_by(key_id=key.key_id).order_by(NewsKeyword.news_id.desc()).limit(5)
if not nk.count():
iter -= 1
continue
list = []
for data in nk:
result = Article.query.filter_by(id=data.news_id).first()
news = article_schema.dump(result)
if news.data not in lists:
list.append(news.data)
lists.append(news.data)
dict["key1"] = list
elif iter == 2:
nk = NewsKeyword.query.filter_by(key_id=key.key_id).order_by(NewsKeyword.news_id.desc()).limit(4)
if not nk.count():
print "hey"
iter -= 1
continue
list = []
for data in nk:
result = Article.query.filter_by(id=data.news_id).first()
news = article_schema.dump(result)
if news.data not in lists:
list.append(news.data)
lists.append(news.data)
dict["key2"] = list
elif iter == 3:
nk = NewsKeyword.query.filter_by(key_id=key.key_id).order_by(NewsKeyword.news_id.desc()).limit(3)
if not nk.count():
iter -= 1
continue
list = []
for data in nk:
result = Article.query.filter_by(id=data.news_id).first()
news = article_schema.dump(result)
if news.data not in lists:
list.append(news.data)
lists.append(news.data)
dict["key3"] = list
else:
nk = NewsKeyword.query.filter_by(key_id=key.key_id).order_by(NewsKeyword.news_id.desc()).limit(2)
if not nk.count():
iter -= 1
continue
list = []
for data in nk:
result = Article.query.filter_by(id=data.news_id).first()
news = article_schema.dump(result)
if news.data not in lists:
list.append(news.data)
lists.append(news.data)
dict["key"+str(iter)] = list
return jsonify({'news': dict})
# farji
@app.route('/preference')
def preference():
return render_template("preferencetry.html")
@app.route('/search_tag/<search>', methods=['GET', 'POST'])
def search_tag(search):
#if request.method == 'POST':
data = search_to_json(search)
return jsonify({'searched': data})
@app.route('/tweet')
def tweet():
return render_template('tweet.html')
# return render_template('pref.html')
@app.route('/android_receive', methods=['GET', 'POST'])
def android_receive():
if request.method == 'POST':
array = request.get_json(force=True)
print array['email']
arr = array['key'][1:-1]
list = arr.split(',')
# arr = json.dumps(array)
# print arr['email']
# print arr['key']
# fnlist = []
# for l in list:
# fnlist.append(l[1:-1])
uid = (User.query.filter_by(email=array['email']).first()).id
for keyword in list:
print keyword
k = Keyword.query.filter_by(key_name=keyword).first()
if k is None:
continue
if not UserKeyword.query.filter_by(key_id=k.id, user_id=uid).count():
uk = UserKeyword(user_id=uid, key_id=k.id, priority=0.5)
db.session.add(uk)
db.session.commit()
else:
uk = UserKeyword.query.filter_by(key_id=k.id, user_id=uid).first()
uk.priority += 0.5
db.session.commit()
return jsonify({'result': 'success'})
@app.route('/receive_keywords', methods=['GET', 'POST'])
def receive_keywords():
if request.method == 'POST':
user = User.query.filter_by(id=current_user.id).first()
user.general += 1
db.session.commit()
array = request.form.get('json_str') # list of keywords
str = array[1:-1]
list = str.split(',')
fnlist = []
for l in list:
fnlist.append(l[1:-1])
for keyword in fnlist:
k = Keyword.query.filter_by(key_name=keyword).first()
if not UserKeyword.query.filter_by(key_id=k.id, user_id=current_user.id).count():
uk = UserKeyword(user_id=current_user.id, key_id=k.id, priority=0.5)
db.session.add(uk)
db.session.commit()
else:
uk = UserKeyword.query.filter_by(key_id=k.id, user_id=current_user.id).first()
uk.priority += 0.5
db.session.commit()
return render_template('personal.html')
def entity_extract(Id, text, news):
from monkeylearn import MonkeyLearn
ml = MonkeyLearn('f61694907b120433ddc66da1880d537c5f9d8f1e')
text_list = [text]
module_id = 'ex_isnnZRbS'
res = ml.extractors.extract(module_id, text_list)
for row in res.result[0]:
if not db.session.query(Keyword).filter(Keyword.key_name == row['entity']).count():
key = Keyword(key_name=row["entity"])
db.session.add(key)
db.session.commit()
else:
key = Keyword.query.filter_by(key_name=row["entity"]).first()
if news:
nk = NewsKeyword(news_id=Id, key_id=key.id)
db.session.add(nk)
db.session.commit()
else:
# if not UserKeyword.query.filter_by(key_id=key.id, user_id=Id).count(): #may not be needed
uk = UserKeyword(user_id=Id, key_id=key.id, priority=1)
db.session.add(uk)
db.session.commit()
# else:
# uk = UserKeyword.query.filter_by(key_id=key.id).first()
# uk.priority += 1
# db.session.commit()
def newsClick(Id):
nk = NewsKeyword.query.filter_by(news_id=Id).all()
for row in nk:
if not db.session.query(UserKeyword).filter(UserKeyword.key_id == row.key_id, UserKeyword.user_id == current_user.id).count():
uk = UserKeyword(key_id=row.key_id, user_id=current_user.id, priority=0.1)
db.session.add(uk)
db.session.commit()
else:
uk = db.session.query(UserKeyword).filter(UserKeyword.key_id == row.key_id, UserKeyword.user_id == current_user.id).first()
uk.priority += 0.1
db.session.commit()
@app.before_first_request
def init_request():
db.create_all()
db.create_all()
#db.drop_all()
if __name__ == '__main__':
# we define the debug environment only if running through command
app.config['SQLALCHEMY_ECHO'] = True
app.run(debug=False)
#trend = 'python'
#req = urllib2.Request('http://http://prractice.herokuapp.com/trends/>' + trend)
#response = urllib2.urlopen(req)
#the_page = response.read()