This repository has been archived by the owner on Dec 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
67 lines (51 loc) · 1.64 KB
/
manage.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
#!/usr/bin/env python
from flaskext.script import Manager
import pygraz_website
from pygraz_website import models, db
import tweepy
import settings
app = pygraz_website.create_app(config_object=settings)
manager = Manager(app)
@manager.option("--dry-run", dest='dryrun', action='store_true')
@manager.command
def sync_twitter(dryrun=False):
last_tweet = models.Tweet.query\
.order_by(models.Tweet.created_at.desc()).first()
last_id = None
if last_tweet:
print "Last ID: " + str(last_tweet.external_id)
last_id = last_tweet.external_id
for tweet in tweepy.Cursor(tweepy.api.user_timeline, 'pygraz',
since_id=last_id).items(100):
if dryrun:
print tweet.id
else:
db.session.add(models.Tweet.from_tweet(tweet))
db.session.commit()
@manager.command
def create_db():
db.create_all()
@manager.command
def runserver():
app.run()
@manager.option('--make-admin', dest='make_admin', action='store')
@manager.command
def update_user(openid, make_admin=None):
user = db.session.query(models.OpenID)\
.filter(models.OpenID.id == openid)\
.first().user
print user
if make_admin == '1':
user.is_admin = True
elif make_admin == '0':
user.is_admin = False
db.session.add(user)
db.session.commit()
@manager.command
def send_meetup_notification(meetup_date):
from pygraz_website.views.meetups import _get_meetup
from pygraz_website.views.account import handle_meetup_created
meetup = _get_meetup(meetup_date)
handle_meetup_created(meetup)
if __name__ == '__main__':
manager.run()