def index(group_alias = None): if not session.get('logged_in'): return render_template('welcome.html', group_alias=group_alias) else: user = get_current_user() create_db() #Event.import_user_facebook_events(user, session['oauth_token'][0]) #Event.import_friends_facebook_events(user, session['oauth_token'][0]) # TODO FIXME remove #oauth_token = session['oauth_token'][0] #graph = GraphAPI(oauth_token) #events = graph.get_connections("me", "events", fields='name,description,id,start_time,end_time,location,venue') #return json.dumps(events) # figure out group stuff group = get_group(group_alias) if group and group not in user.groups: user.groups.append(group) db.session.commit() # generate forms trip = Trip(user.id) trip_form = NewTripForm(obj=trip, secret_key=os.environ[SECRET_KEY]) if group: event = Event(user.id, group.id) else: event = Event(user.id) event_form = NewEventForm(obj=event, secret_key=os.environ[SECRET_KEY]) meal = Meal(user.id) meal_form = NewMealForm(obj=meal, secret_key=os.environ[SECRET_KEY]) fbgroup = Fbgroup(user.id) fbgroup_form = NewFbgroupForm(obj=fbgroup, secret_key=os.environ[SECRET_KEY]) # see if we need to ask user to add trip trip_count = Trip.query.filter_by(user_id=user.id).count() show_prompt = (trip_count == 0) return render_template('main.html', group_alias=group_alias, group=group, trip_form=trip_form, event_form=event_form, meal_form=meal_form, fbgroup_form=fbgroup_form, show_prompt=show_prompt)
def list_of_currency(message): try: obj = model.LastRequest.select()[0] except Exception: data = requests.get('https://api.exchangeratesapi.io/latest?base=USD').json() res = list() for el in data['rates']: rate = '{:.2f}'.format(float(data['rates'][el])) res.append(str(el) + ':' + str(rate)) model.create_db('\n'.join([str(elem) for elem in res]), datetime.now()) bot.send_message(message.chat.id, '\n'.join([str(elem) for elem in res])) return if obj.time > datetime.now() - timedelta(minutes=10): bot.send_message(message.chat.id, obj.data) print(obj.time - timedelta(minutes=10)) else: data = requests.get('https://api.exchangeratesapi.io/latest?base=USD').json() res = list() for el in data['rates']: rate = '{:.2f}'.format(float(data['rates'][el])) res.append(str(el) + ':' + str(rate)) model.update_db('\n'.join([str(elem) for elem in res]), datetime.now()) print(2) bot.send_message(message.chat.id, '\n'.join([str(elem) for elem in res]))
def setUpClass(self): print "in setup class" #reset test database model.session.execute('DELETE FROM doulas') model.session.execute('DELETE FROM parents') model.create_db()
def main(): model.create_db() load_participants() load_preferences() # load_route_details() load_part_meals()
def main(datapath, dbpath): model.create_db(datapath, dbpath)
app.config['SECRET_KEY'] = secret_key # connect to db connstr = 'postgresql://{0}:{1}@{2}/{3}'.format(dbuser, dbpass, dbhost, dbname) app.config['DEBUG'] = True app.config['SQLALCHEMY_DATABASE_URI'] = connstr app.config['SECURITY_LOGIN_USER_TEMPLATE'] = 'login.min.html' app.config['SECURITY_MSG_USER_DOES_NOT_EXIST'] = (u"אין חשבון משוייך לכתובת דואר אלקטרוני זו", 'error') app.config['SECURITY_MSG_INVALID_PASSWORD'] = (u"כתובת דואר אלקטרוני וססמה אינם תואמים", 'error') # loading db and model import model model.app = app model.init() model.inithash(hash) from model import decodehash, events, users model.create_db() users.init(app) # Flask-Login from flask.ext.login import LoginManager, login_user, logout_user # Flask-Security from flask.ext.security import Security, current_user, login_required # Flask-WTF from flask_wtf import Form from wtforms import TextField, StringField, PasswordField, validators from wtforms.validators import Required, DataRequired from datetime import datetime
import model model.create_db() #model.save_user_to_db('admin','admin')
def seUpClass(self): print os.environ['DATABASE_URL'] model.create_db()
def hello(): create_db() return "Hello from Python yay!"
except IntegrityError: return json.dumps({'status': False}) api.add_resource(ExchangeList, '/grab_and_save') api.add_resource(LastExchange, '/last') api.add_resource(LastExchangeByCurrency, '/last/<string:currency>') api.add_resource(LastNExchanges, '/last/<int:n>') api.add_resource(LastNExchangesByCurrency, '/last/<string:currency>/<int:n>') def create_tables(): """ Create tables on the db """ try: db.create_all() return True except IntegrityError: return False # run app service if __name__ == "__main__": # TODO: Find a real solution to this problem import time time.sleep(5) create_db() create_tables() app.run(host="0.0.0.0", port=8082, debug=True)