def locations_subscribe(language_suffix, location_suffix): save_lang(language_suffix) save_loc(location_suffix) try: form = SubscriptionForm() if form.validate_on_submit(): email = form.email.data if not email: return jsonify({'CODE' : '3', 'TEXT' : gettext('Set email address, please')}) if db.session.query(Subscription).filter_by(email=email).count()>0: return jsonify({'CODE' : '2', 'TEXT' : gettext("You're already subscribed. Thank you!")}) subscriber = Subscription(dt=datetime.datetime.now(), location_id=session['locations'][location_suffix], email=email) db.session.add(subscriber) mc = mailchimp.Mailchimp(app.config['MAILCHIMP_TOKEN']) mc.lists.subscribe(app.config['MAILCHIMP_SUBSCRIPTION_LIST_ID'], {'email': email, 'double_optin' : false, 'send_welcome' : true}) db.session.commit() return jsonify({ 'CODE' : '0', 'TEXT' : gettext("Great! You're sucessfully subscribed.") }) else: return jsonify({'CODE' : '4', 'TEXT' : gettext("Incorrect format of the Email")}) except mailchimp.ListAlreadySubscribedError: return jsonify({'CODE' : '2', 'TEXT' : gettext("You're already subscribed. Thank you!")}) except mailchimp.Error, e: return jsonify({'CODE' : '1', 'TEXT' : gettext("An error occured. Please repeat.")})
def events_attend(language_suffix, location_suffix, event_id): save_lang(language_suffix) save_loc(location_suffix) smsc = SMSC() msg = gettext("Your promocode: _code_. See you!").replace('_code_', '123123') phone = re.sub("[^0-9]", "", request.form['phone']) print phone if phone[0] in ['7', '8']: phone = phone[1:] phone = '7'+phone print phone if not re.match(r"\d{10}", phone): return jsonify({'CODE' : '1', 'TEXT' : gettext("Incorrect format")}) sms_info = smsc.get_sms_cost(phone, msg) ''' sms_info[0] - sms cost sms_info[1] - sms count ''' if float(sms_info[0]) > 3 : return jsonify({'CODE' : '2', 'TEXT' : gettext("We can't send the sms to this number")}) sended_sms_info = smsc.send_sms(phone, msg, sender="apresworkco") return jsonify({ 'CODE' : '0', 'TEXT' : gettext("Great! When the count of people will be enough, we will send promo-code to you in sms.") }) '''
def disciplines_s_list(language_suffix, location_suffix): save_lang(language_suffix) save_loc(location_suffix) return redirect(url_for( 'disciplines_list', language_suffix=language_suffix, location_suffix=location_suffix ))
def news_s_page(language_suffix, location_suffix, id): save_lang(language_suffix) save_loc(location_suffix) return redirect( url_for('news_page', language_suffix=language_suffix, location_suffix=location_suffix, id=id))
def events_s_list(language_suffix, location_suffix): save_lang(language_suffix) save_loc(location_suffix) return redirect(url_for( 'events', language_suffix=language_suffix, location_suffix=location_suffix ))
def news_s_list(language_suffix, location_suffix): save_lang(language_suffix) save_loc(location_suffix) return redirect( url_for( 'news_list', language_suffix=language_suffix, location_suffix=location_suffix, ))
def locations_index(language_suffix, location_suffix): save_lang(language_suffix) save_loc(location_suffix) form = SubscriptionForm() return render_template('l_index.html', language_suffix = language_suffix, location_suffix = location_suffix, form=form, debug=app.debug)
def events_page(language_suffix, location_suffix, id): save_lang(language_suffix) save_loc(location_suffix) event = Event.query.filter(Event.id==id).first() return render_template('p_event.html', language_suffix = language_suffix, location_suffix = location_suffix, event=event, debug=app.debug)
def riders_page(language_suffix, location_suffix, id): save_lang(language_suffix) save_loc(location_suffix) rider = Rider.query.filter(Rider.id == id).first() return render_template('p_rider.html', language_suffix=language_suffix, location_suffix=location_suffix, rider=rider, debug=app.debug)
def cameramen_page(language_suffix, location_suffix, id): save_lang(language_suffix) save_loc(location_suffix) cameraman = Cameraman.query.filter(Cameraman.id == id).first() return render_template('p_cameraman.html', language_suffix=language_suffix, location_suffix=location_suffix, rand=random.randint(1, 1000000), cameraman=cameraman, debug=app.debug)
def news_page(language_suffix, location_suffix, id): save_lang(language_suffix) save_loc(location_suffix) news = News.query.filter(News.id == id).first() return render_template('p_news.html', language_suffix=language_suffix, location_suffix=location_suffix, rand=random.randint(1, 1000000), news=news, debug=app.debug)
def resorts_list(language_suffix, location_suffix): save_lang(language_suffix) save_loc(location_suffix) cbr = {} resorts = db.session.query(Resort).filter(Resort.location_id==get_loc_id()).all() #get_loc_id() location = db.session.query(Location).filter(Location.suffix==get_loc()).first() for resort in resorts: share_text = resort.share_text.replace('_url_', get_site_url()+url_for('resorts_s_list', language_suffix=language_suffix, location_suffix=location_suffix)+'#id'+str(resort.id)) share_text = share_text.encode('utf-8') share_text = urllib.quote(share_text) cbr[resort.id] = { 'ID' : resort.id, 'NAME' : resort.name, 'PHONE' : resort.phone, 'ADDRESS' : resort.address, 'URL_SITE' : resort.url_site, 'URL_IG' : resort.url_ig, 'URL_VK' : resort.url_vk, 'URL_FB' : resort.url_fb, 'URL_IMG': resort.url_img, 'LA' : resort.la, 'LO' : resort.lo, 'OWM_ID' : resort.owm_id, 'DESCRIPTION' : resort.description, 'SHARE_TEXT' : share_text, 'CAMERAS' : [] } webcameras = db.session.query(Resort, Webcamera).join(Webcamera).filter(Resort.location_id==get_loc_id()).all() for camera in webcameras: cbr[camera.Resort.id]['CAMERAS'].append({ 'ID' : camera.Webcamera.id, 'NAME' : camera.Webcamera.name, 'IMG_LINK' : camera.Webcamera.img_link, 'IFRAME_LINK' : camera.Webcamera.iframe_link, 'IMG_NA' : camera.Webcamera.img_na, 'LOAD_FROM_IFRAME' : camera.Webcamera.load_from_iframe }) return render_template('l_resorts.html', language_suffix = language_suffix, location_suffix = location_suffix, resorts = cbr, location_header = location.resorts_header, location_subheader = location.resorts_subheader, rand=random.randint(1,1000000), debug=app.debug)
def events_list(language_suffix, location_suffix): save_lang(language_suffix) save_loc(location_suffix) return render_template('not_ready.html', language_suffix = language_suffix, location_suffix = location_suffix, countdown_time = 'May 3, 2015 15:03:25', debug=app.debug) events = Event.query.filter(Event.resort.has(location_id=get_loc_id())).all() return render_template('l_events.html', language_suffix = language_suffix, location_suffix = location_suffix, rand=random.randint(1,1000000), events=events, debug=app.debug)
def riders_list(language_suffix, location_suffix): save_lang(language_suffix) save_loc(location_suffix) return render_template('not_ready.html', language_suffix=language_suffix, location_suffix=location_suffix, countdown_time='May 14, 2015 15:03:25', debug=app.debug) riders = Rider.query.filter(Rider.location_id == get_loc_id()).all() return render_template('l_riders.html', language_suffix=language_suffix, location_suffix=location_suffix, rand=random.randint(1, 1000000), riders=riders, debug=app.debug)
def news_list(language_suffix, location_suffix): save_lang(language_suffix) save_loc(location_suffix) return render_template('not_ready.html', language_suffix=language_suffix, location_suffix=location_suffix, countdown_time='May 11, 2015 15:03:25', debug=app.debug) news = News.query.filter(News.location_id == get_loc_id()).all() return render_template('l_news.html', language_suffix=language_suffix, location_suffix=location_suffix, rand=random.randint(1, 1000000), news=news, debug=app.debug)
def resorts_page(language_suffix, location_suffix, id): save_lang(language_suffix) save_loc(location_suffix) resort = db.session.query(Resort).filter(Resort.id==id).first() location = db.session.query(Location).filter(Location.suffix==get_loc()).first() share_text = resort.share_text.replace('_url_', get_site_url()+url_for('resorts_s_page', language_suffix=language_suffix, location_suffix=location_suffix, id=resort.id)) share_text = share_text.encode('utf-8') share_text = urllib.quote(share_text) resort_obj = { 'ID' : resort.id, 'NAME' : resort.name, 'PHONE' : resort.phone, 'ADDRESS' : resort.address, 'URL_SITE' : resort.url_site, 'URL_IG' : resort.url_ig, 'URL_VK' : resort.url_vk, 'URL_FB' : resort.url_fb, 'URL_IMG': resort.url_img, 'LA' : resort.la, 'LO' : resort.lo, 'OWM_ID' : resort.owm_id, 'DESCRIPTION' : resort.description, 'SHARE_TEXT' : share_text, 'HOW_TO_GET' : resort.how_to_get, 'CAMERAS' : [] } webcameras = db.session.query(Resort, Webcamera).join(Webcamera).filter(Resort.id==id).all() for camera in webcameras: resort_obj['CAMERAS'].append({ 'ID' : camera.Webcamera.id, 'NAME' : camera.Webcamera.name, 'IMG_LINK' : camera.Webcamera.img_link, 'IFRAME_LINK' : camera.Webcamera.iframe_link, 'IMG_NA' : camera.Webcamera.img_na, 'LOAD_FROM_IFRAME' : camera.Webcamera.load_from_iframe }) return render_template('p_resort.html', language_suffix = language_suffix, location_suffix = location_suffix, resort = resort_obj, rand=random.randint(1,1000000), debug=app.debug)
def cameramen_list(language_suffix, location_suffix): save_lang(language_suffix) save_loc(location_suffix) return render_template('not_ready.html', language_suffix=language_suffix, location_suffix=location_suffix, countdown_time='May 7, 2015 15:03:25', debug=app.debug) cameramen = Cameraman.query.filter( Cameraman.location_id == get_loc_id()).all() return render_template('l_cameramen.html', language_suffix=language_suffix, location_suffix=location_suffix, rand=random.randint(1, 1000000), cameramen=cameramen, debug=app.debug)
def camps_page(language_suffix, id): save_curr('camps_page') lang = save_lang(language_suffix) loc = save_loc() camp = Camp.query.filter(Camp.id == id).first() top_slides = camp.slider_block.first().slides top_info_block = camp.top_info_block.first() services_block = camp.services.first() staff_block = camp.staff.first() main_info_block = camp.main_info_block.first() signup_block = camp.signup_form.first() partners_block = camp.partners.first() contact_block = camp.contact_form.first() mailchimp_list_token = get_data_by_lang( signup_block, '_mailchimp_token', 'en') # get_mailchimp_list_id(lang) mc = mailchimp.Mailchimp(app.config['MAILCHIMP_TOKEN']) mailchimp_form = {} try: mailchimp_form = mc.lists.merge_vars({'id': mailchimp_list_token}) mailchimp_form = mailchimp_form['data'][0]['merge_vars'] except Exception, e: print e
def getweather(location_suffix): result = {'success': 'true', 'resorts': {}} #try: if True: location_suffix = save_loc(location_suffix) #API_key=app.config['OWM_KEY'], owm = OWM(config_module='pyowm_config', language='ru') resorts = db.session.query(Resort).filter_by( location_id=get_loc_id()).all() if len(resorts) > 0: for resort in resorts: if not resort.owm_id: continue observation = owm.weather_at_id(resort.owm_id) current_hour = datetime.now().hour today_night = datetime(datetime.now().year, datetime.now().month, datetime.now().day, 3, 0, 0) today_morning = datetime(datetime.now().year, datetime.now().month, datetime.now().day, 9, 0, 0) today_day = datetime(datetime.now().year, datetime.now().month, datetime.now().day, 14, 0, 0) today_evening = datetime(datetime.now().year, datetime.now().month, datetime.now().day, 19, 0, 0) tomorrow_night = today_night + timedelta(days=1) tomorrow_morning = today_morning + timedelta(days=1) tomorrow_day = today_day + timedelta(days=1) tomorrow_evening = today_evening + timedelta(days=1) #next_day = datetime.now() + timedelta(days=1) #next_3h = datetime.now() + timedelta(hours=3) #next_6h = datetime.now() + timedelta(hours=6) current_weather = observation.get_weather() forecast_weather = owm.three_hours_forecast_at_id( resort.owm_id) #in3h_weather = forecast_weather.get_weather_at(next_3h) #in6h_weather = forecast_weather.get_weather_at(next_6h) #in24h_weather = forecast_weather.get_weather_at(next_day) today_night_weather = forecast_weather.get_weather_at( today_night) if current_hour < 4 else False today_morning_weather = forecast_weather.get_weather_at( today_morning) if current_hour < 10 else False today_day_weather = forecast_weather.get_weather_at( today_day) if current_hour < 15 else False today_evening_weather = forecast_weather.get_weather_at( today_evening) if current_hour < 20 else False tomorrow_night_weather = forecast_weather.get_weather_at( tomorrow_night) tomorrow_morning_weather = forecast_weather.get_weather_at( tomorrow_morning) tomorrow_day_weather = forecast_weather.get_weather_at( tomorrow_day) tomorrow_evening_weather = forecast_weather.get_weather_at( tomorrow_evening) #print str(current_weather) #print current_weather_object = { 'temp': str( current_weather.get_temperature( unit='celsius')['temp']) + u'\u00B0C', 'temp_interval': u'от ' + str( current_weather.get_temperature( unit='celsius')['temp_min']) + u'\u00B0C до ' + str( current_weather.get_temperature( unit='celsius')['temp_max']) + u'\u00B0C', 'detailed_status': current_weather.get_detailed_status(), 'icon': weather_icons_map[current_weather.get_weather_icon_name()], 'wind': { 'speed': current_weather.get_wind()['speed'], 'deg': current_weather.get_wind()['deg'], 'speed_icon': 'wi-beafort-' + str(int(round(current_weather.get_wind()['speed']))), 'deg_icon': '_' + str( round_to_base(current_weather.get_wind()['deg'], 15)) + '-deg', 'bad_deg': resort.bad_wind_direction }, 'clouds': current_weather.get_clouds() } if today_night_weather: today_night_weather_object = { 'temp': str( today_night_weather.get_temperature( unit='celsius')['temp']) + u'\u00B0C', 'temp_interval': u'от ' + str( today_night_weather.get_temperature( unit='celsius')['temp_min']) + u'\u00B0C до ' + str( current_weather.get_temperature( unit='celsius')['temp_max']) + u'\u00B0C', 'detailed_status': today_night_weather.get_detailed_status(), 'icon': weather_icons_map[ today_night_weather.get_weather_icon_name()], 'wind': { 'speed': today_night_weather.get_wind()['speed'], 'deg': today_night_weather.get_wind()['deg'], 'speed_icon': 'wi-beafort-' + str( int( round(today_night_weather.get_wind() ['speed']))), 'deg_icon': '_' + str( round_to_base( today_night_weather.get_wind()['deg'], 15)) + '-deg', 'bad_deg': resort.bad_wind_direction }, 'clouds': today_night_weather.get_clouds() } else: today_night_weather_object = {} if today_night_weather: today_night_weather_object = { 'temp': str( today_night_weather.get_temperature( unit='celsius')['temp']) + u'\u00B0C', 'temp_interval': u'от ' + str( today_night_weather.get_temperature( unit='celsius')['temp_min']) + u'\u00B0C до ' + str( current_weather.get_temperature( unit='celsius')['temp_max']) + u'\u00B0C', 'detailed_status': today_night_weather.get_detailed_status(), 'icon': weather_icons_map[ today_night_weather.get_weather_icon_name()], 'wind': { 'speed': today_night_weather.get_wind()['speed'], 'deg': today_night_weather.get_wind()['deg'], 'speed_icon': 'wi-beafort-' + str( int( round(today_night_weather.get_wind() ['speed']))), 'deg_icon': '_' + str( round_to_base( today_night_weather.get_wind()['deg'], 15)) + '-deg', 'bad_deg': resort.bad_wind_direction }, 'clouds': today_night_weather.get_clouds() } else: today_night_weather_object = {} if today_morning_weather: today_morning_weather_object = { 'temp': str( today_morning_weather.get_temperature( unit='celsius')['temp']) + u'\u00B0C', 'temp_interval': gettext('from') + ' ' + str( today_morning_weather.get_temperature( unit='celsius')['temp_min']) + u'\u00B0C ' + gettext('to') + ' ' + str( current_weather.get_temperature( unit='celsius')['temp_max']) + u'\u00B0C', 'detailed_status': today_morning_weather.get_detailed_status(), 'icon': weather_icons_map[ today_morning_weather.get_weather_icon_name()], 'wind': { 'speed': today_morning_weather.get_wind()['speed'], 'deg': today_morning_weather.get_wind()['deg'], 'speed_icon': 'wi-beafort-' + str( int( round(today_morning_weather.get_wind() ['speed']))), 'deg_icon': '_' + str( round_to_base( today_morning_weather.get_wind()['deg'], 15)) + '-deg', 'bad_deg': resort.bad_wind_direction }, 'clouds': today_morning_weather.get_clouds() } else: today_morning_weather_object = {} if today_day_weather: today_day_weather_object = { 'temp': str( today_day_weather.get_temperature( unit='celsius')['temp']) + u'\u00B0C', 'temp_interval': gettext('from') + ' ' + str( today_day_weather.get_temperature( unit='celsius')['temp_min']) + u'\u00B0C ' + gettext('to') + ' ' + str( current_weather.get_temperature( unit='celsius')['temp_max']) + u'\u00B0C', 'detailed_status': today_day_weather.get_detailed_status(), 'icon': weather_icons_map[ today_day_weather.get_weather_icon_name()], 'wind': { 'speed': today_day_weather.get_wind()['speed'], 'deg': today_day_weather.get_wind()['deg'], 'speed_icon': 'wi-beafort-' + str( int( round(today_day_weather.get_wind() ['speed']))), 'deg_icon': '_' + str( round_to_base( today_day_weather.get_wind()['deg'], 15)) + '-deg', 'bad_deg': resort.bad_wind_direction }, 'clouds': today_day_weather.get_clouds() } else: today_day_weather_object = {} if today_evening_weather: today_evening_weather_object = { 'temp': str( today_evening_weather.get_temperature( unit='celsius')['temp']) + u'\u00B0C', 'temp_interval': gettext('from') + ' ' + str( today_evening_weather.get_temperature( unit='celsius')['temp_min']) + u'\u00B0C ' + gettext('to') + ' ' + str( current_weather.get_temperature( unit='celsius')['temp_max']) + u'\u00B0C', 'detailed_status': today_evening_weather.get_detailed_status(), 'icon': weather_icons_map[ today_evening_weather.get_weather_icon_name()], 'wind': { 'speed': today_evening_weather.get_wind()['speed'], 'deg': today_evening_weather.get_wind()['deg'], 'speed_icon': 'wi-beafort-' + str( int( round(today_evening_weather.get_wind() ['speed']))), 'deg_icon': '_' + str( round_to_base( today_evening_weather.get_wind()['deg'], 15)) + '-deg', 'bad_deg': resort.bad_wind_direction }, 'clouds': today_evening_weather.get_clouds() } else: today_evening_weather_object = {} tomorrow_night_weather_object = { 'temp': str( tomorrow_night_weather.get_temperature( unit='celsius')['temp']) + u'\u00B0C', 'temp_interval': gettext('from') + ' ' + str( tomorrow_night_weather.get_temperature( unit='celsius')['temp_min']) + u'\u00B0C ' + gettext('to') + ' ' + str( current_weather.get_temperature( unit='celsius')['temp_max']) + u'\u00B0C', 'detailed_status': tomorrow_night_weather.get_detailed_status(), 'icon': weather_icons_map[ tomorrow_night_weather.get_weather_icon_name()], 'wind': { 'speed': tomorrow_night_weather.get_wind()['speed'], 'deg': tomorrow_night_weather.get_wind()['deg'], 'speed_icon': 'wi-beafort-' + str( int( round(tomorrow_night_weather.get_wind() ['speed']))), 'deg_icon': '_' + str( round_to_base( tomorrow_night_weather.get_wind()['deg'], 15)) + '-deg', 'bad_deg': resort.bad_wind_direction }, 'clouds': tomorrow_night_weather.get_clouds() } tomorrow_morning_weather_object = { 'temp': str( tomorrow_morning_weather.get_temperature( unit='celsius')['temp']) + u'\u00B0C', 'temp_interval': gettext('from') + ' ' + str( tomorrow_morning_weather.get_temperature( unit='celsius')['temp_min']) + u'\u00B0C ' + gettext('to') + ' ' + str( current_weather.get_temperature( unit='celsius')['temp_max']) + u'\u00B0C', 'detailed_status': tomorrow_morning_weather.get_detailed_status(), 'icon': weather_icons_map[ tomorrow_morning_weather.get_weather_icon_name()], 'wind': { 'speed': tomorrow_morning_weather.get_wind()['speed'], 'deg': tomorrow_morning_weather.get_wind()['deg'], 'speed_icon': 'wi-beafort-' + str( int( round(tomorrow_morning_weather.get_wind() ['speed']))), 'deg_icon': '_' + str( round_to_base( tomorrow_morning_weather.get_wind()['deg'], 15)) + '-deg', 'bad_deg': resort.bad_wind_direction }, 'clouds': tomorrow_morning_weather.get_clouds() } tomorrow_day_weather_object = { 'temp': str( tomorrow_day_weather.get_temperature( unit='celsius')['temp']) + u'\u00B0C', 'temp_interval': gettext('from') + ' ' + str( tomorrow_day_weather.get_temperature( unit='celsius')['temp_min']) + u'\u00B0C ' + gettext('to') + ' ' + str( current_weather.get_temperature( unit='celsius')['temp_max']) + u'\u00B0C', 'detailed_status': tomorrow_day_weather.get_detailed_status(), 'icon': weather_icons_map[ tomorrow_day_weather.get_weather_icon_name()], 'wind': { 'speed': tomorrow_day_weather.get_wind()['speed'], 'deg': tomorrow_day_weather.get_wind()['deg'], 'speed_icon': 'wi-beafort-' + str( int(round( tomorrow_day_weather.get_wind()['speed']))), 'deg_icon': '_' + str( round_to_base( tomorrow_day_weather.get_wind()['deg'], 15)) + '-deg', 'bad_deg': resort.bad_wind_direction }, 'clouds': tomorrow_day_weather.get_clouds() } tomorrow_evening_weather_object = { 'temp': str( tomorrow_evening_weather.get_temperature( unit='celsius')['temp']) + u'\u00B0C', 'temp_interval': gettext('from') + ' ' + str( tomorrow_evening_weather.get_temperature( unit='celsius')['temp_min']) + u'\u00B0C ' + gettext('to') + ' ' + str( current_weather.get_temperature( unit='celsius')['temp_max']) + u'\u00B0C', 'detailed_status': tomorrow_evening_weather.get_detailed_status(), 'icon': weather_icons_map[ tomorrow_evening_weather.get_weather_icon_name()], 'wind': { 'speed': tomorrow_evening_weather.get_wind()['speed'], 'deg': tomorrow_evening_weather.get_wind()['deg'], 'speed_icon': 'wi-beafort-' + str( int( round(tomorrow_evening_weather.get_wind() ['speed']))), 'deg_icon': '_' + str( round_to_base( tomorrow_evening_weather.get_wind()['deg'], 15)) + '-deg', 'bad_deg': resort.bad_wind_direction }, 'clouds': tomorrow_evening_weather.get_clouds() } result['resorts'][resort.id] = { 'current': current_weather_object, 'today_night': today_night_weather_object, 'today_morning': today_morning_weather_object, 'today_day': today_day_weather_object, 'today_evening': today_evening_weather_object, 'tomorrow_night': tomorrow_night_weather_object, 'tomorrow_morning': tomorrow_morning_weather_object, 'tomorrow_day': tomorrow_day_weather_object, 'tomorrow_evening': tomorrow_evening_weather_object } #except Exception as e: # print str(e) # print str(sys.exc_info()) # result = { 'success' : 'false' } return jsonify(result)
def disciplines_list(language_suffix, location_suffix): save_lang(language_suffix) save_loc(location_suffix) return "Sorry, haven't implemented yet =\ "