def import_chapter_url(): try: spreadsheet_id = Settings.get('sheet_id') range_name = Settings.get('sheet_range') config = config_sheet() result = config.service.spreadsheets().values().get( spreadsheetId=spreadsheet_id, range=range_name).execute(http=config.http) values = result.get('values', []) #gdglist = gdgchapterurl.query().fetch() for r in values: #if r[0] not in gdglist: if not gdgchapterurl.query( gdgchapterurl.groupUrlname == r[0]).fetch(): obj = gdgchapterurl() obj.groupUrlname = r[0] obj.put() return 'importing process completed' except: logging.error('error into importing process') raise
def import_spreadsheet(): try: spreadsheet_id = Settings.get('sheet_id') range_name = Settings.get('sheet_range') config = config_sheet() result = config.service.spreadsheets().values().get( spreadsheetId=spreadsheet_id, range=range_name).execute(http=config.http) values = result.get('values', []) for r in values: obj = gdgchapter() obj.groupName = r[0] obj.groupStatus = r[2] obj.groupMembers = int(r[3]) obj.city = r[1] obj.countryMod = r[4] obj.put() return 'importing process completed' except: logging.error('error into importing process') raise
def user(): app.config['BASIC_AUTH_USERNAME'] = Settings.get('user_access') app.config['BASIC_AUTH_PASSWORD'] = Settings.get('pass_access') if (Settings.get('user_access') == "not set") or (Settings.get('pass_access') == "not set"): return 'User Not Confirmed' else: return 'User Confirmed'
async def on_raw_message_edit(message_id, data): channel = client.get_channel(int(data['channel_id'])) try: m = LogMessage.get(channel.guild.id, message_id) except LogMessage.DoesNotExist as e: return try: ts = dateutil.parser.parse(data['edited_timestamp']) except KeyError as e: ts = dt.datetime.utcnow() except TypeError as e: ts = dt.datetime.utcnow() if 'content' in data: rev = LogRevision(content=data['content'], timestamp=ts, pinned=data['pinned']) else: rev = LogRevision(timestamp=ts, pinned=data['pinned']) m.revisions.append(rev) m.save() # pp = pprint.PrettyPrinter(depth=4) # pp.pprint(data) s = Settings.get(channel.guild.id) logchannel = client.get_channel(s.log_channel) if not m.revisions[-2].pinned == m.revisions[-1].pinned: state = pin_status[m.revisions[-1].pinned] await logchannel.send(f'Message {message_id} has been {state}') else: await logchannel.send(f'Message {message_id} has been edited')
def send_mail(their_email, their_message): ''' Send an email message to me ''' message = mail.EmailMessage(sender=app_identity.get_application_id() + '@appspot.gserviceaccount.com>') message.subject = 'Message from Bagbatch Website' message.to = Settings.get('EMAIL') message.body = """From: {}\n\n<<BEGINS>>\n\n{}\n\n<<ENDS>>""".format(their_email, their_message) message.send()
def send_mail(their_email, their_message): ''' Send an email message to me ''' message = mail.EmailMessage(sender=app_identity.get_application_id() + '@appspot.gserviceaccount.com>') message.subject = 'Message from Bagbatch Website' message.to = Settings.get('EMAIL') message.body = """From: {}\n\n<<BEGINS>>\n\n{}\n\n<<ENDS>>""".format( their_email, their_message) message.send()
def get(self): user_address = Settings.get("user_address") if not mail.is_email_valid(user_address): raise ValueError else: sender_address = Settings.get("sender_address") subject = 'Month to Date Grocery spending.' txns = mtd_grocery_transactions() ttl = -sum(txn.amount for txn in txns.values()) body = """Good morning B! You have spent ${:,.2f} this month on groceries.""".format(ttl) body = body + "\n\n" txn_details = "\n".join("{} {:35s} ${:,.2f}".format(str(txn.date), txn.content, -txn.amount) for txn in sorted(txns.values(), key=lambda x: x.date)) body = body + txn_details mail.send_mail(sender_address, user_address, subject, body) logging.info("An Email was sent to {}".format(user_address))
def _request(address): key = Settings.get('GOOGLE_MAPS_API_KEY') url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' + urllib.quote( address) + '&key=' + key res = json.loads(urlfetch.fetch(url).content)['results'] if (len(res) == 0): return None loc = res[0]['geometry']['location'] geo = ndb.GeoPt(loc['lat'], loc['lng']) return GeoCache(address=address, geo=geo)
async def on_raw_message_delete(message_id, channel_id): channel = client.get_channel(channel_id) try: m = LogMessage.get(channel.guild.id, message_id) except LogMessage.DoesNotExist as e: return if m: m.deleted = True m.save() s = Settings.get(channel.guild.id) logchannel = client.get_channel(s.log_channel) await logchannel.send(f'Message {message_id} has been deleted')
def get_current_settings(): try: current_settings = Settings.get(Settings.id == 1) except Settings.DoesNotExist: current_settings = Settings.create(blog_title="Blog", initialized=True, icon_1_link='', icon_1_icon_type='github', icon_2_link='', icon_2_icon_type='linkedin', posts_per_page=10, max_synopsis_chars=500, table_entries_per_page=14) current_settings.save() return current_settings
def admin_settings_save(): try: current_settings = Settings.get(Settings.id == 1) current_settings.blog_title = request.form.get('blog-title') current_settings.icon_1_link = request.form.get('icon-1-link') current_settings.icon_1_icon_type = request.form.get( 'icon-1-icon-type') current_settings.icon_2_link = request.form.get('icon-2-link') current_settings.icon_2_icon_type = request.form.get( 'icon-2-icon-type') current_settings.posts_per_page = request.form.get('posts-per-page') current_settings.max_synopsis_chars = request.form.get( 'max-synopsis-chars') current_settings.table_entries_per_page = request.form.get( 'table-entries-per-page') current_settings.save() flash("Settings updated.", "success") except Settings.DoesNotExist: flash("Please try again.", "danger") return redirect(url_for('admin_settings'))
def task_group(url): client = meetup.api.Client(Settings.get('meetup_key')) group_info = client.GetGroup({'urlname': url}) check_chapter = gdgchapter.query(gdgchapter.groupUrl == url).fetch() cn_name_format = COUNTRY_NAME_FORMAT_DEFAULT if not check_chapter: obj = gdgchapter() obj.groupid = str(group_info.id) obj.groupUrl = url obj.groupName = group_info.name obj.countryMod = country_alpha2_to_country_name( group_info.country, cn_name_format) obj.groupStatus = group_info.status obj.city = group_info.city obj.groupMembers = group_info.members obj.put() return make_response("task executed")
def get_settings(self): try: return Settings.get(Settings.user == self.user_id) except Settings.DoesNotExist: return Settings.create(user=self.user_id)
import logging import sys import traceback import forms from models import Settings from flask import Flask, render_template from google.appengine.api import app_identity # pylint: disable=E0401 from google.appengine.api import mail # pylint: disable=E0401 from google.appengine.api import users import pdb # Initialize the application with CSRF app = Flask(__name__) # pylint: disable=invalid-name # Set the Flask debug to false so you can use GAE debug app.config.update(DEBUG=False) app.secret_key = Settings.get('SECRET_KEY') app.config['RECAPTCHA_USE_SSL'] = False app.config['RECAPTCHA_PUBLIC_KEY'] = Settings.get('RECAPTCHA_PUBLIC_KEY') app.config['RECAPTCHA_PRIVATE_KEY'] = Settings.get('RECAPTCHA_PRIVATE_KEY') app.config['RECAPTCHA_OPTIONS'] = {'theme': 'white'} @app.before_request def enable_local_error_handling(): ''' test of log ''' app.logger.addHandler(logging.StreamHandler()) app.logger.setLevel(logging.INFO) @app.route('/', methods=['GET', 'POST']) def form():
import meetup.api import googleapiclient.discovery from oauth2client.contrib.appengine import AppAssertionCredentials from google.appengine.api import memcache from google.appengine.api import urlfetch from google.appengine.api import taskqueue urlfetch.set_default_fetch_deadline(180) app = Flask(__name__, static_url_path="") basic_auth = BasicAuth(app) from gdg.models import gdgchapter, gdgchapterurl from models import Settings app.config['BASIC_AUTH_USERNAME'] = Settings.get('user_access') app.config['BASIC_AUTH_PASSWORD'] = Settings.get('pass_access') @app.route('/api/userconfirmation', methods=['POST']) def user(): app.config['BASIC_AUTH_USERNAME'] = Settings.get('user_access') app.config['BASIC_AUTH_PASSWORD'] = Settings.get('pass_access') if (Settings.get('user_access') == "not set") or (Settings.get('pass_access') == "not set"): return 'User Not Confirmed' else: return 'User Confirmed'
def view(request, path): lang_code = None if request.META.has_key('HTTP_ACCEPT_LANGUAGE'): preferred_langs = [lang.split(';')[0].strip() for lang in request.META['HTTP_ACCEPT_LANGUAGE'].split(',')] # TODO: Implement priority handling (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html) lang_code = preferred_langs[0] lang_code = lang_code.split('-')[0] try: lang = Language.objects.filter(code=lang_code).get() except: lang = None location = Location.objects.filter(location=path).get() page = location.page _links = Link.objects.filter(visible=True).order_by('position') links = [] if lang: try: page = PageTranslation.objects.filter(language=lang, page=page).get() except: settings = Settings() page = PageTranslation.objects.filter(language=Language.objects.filter(code=settings.get('default_language', 'en')).get(), page=page).get() for link in _links: try: t = LinkTranslation.objects.filter(language=lang, link=link).get() t.location = link.location links.append(t) except: links.append(link) p = plugins.Plugin('guestbook') content = mark_safe(p.process(page.content)) title = page.title return render_to_response('view.html', { 'content': content, 'title': title, 'page': page, 'links': links, })
import logging import sys import traceback import forms from models import Settings from flask import Flask, render_template from google.appengine.api import app_identity # pylint: disable=E0401 from google.appengine.api import mail # pylint: disable=E0401 from google.appengine.api import users import pdb # Initialize the application with CSRF app = Flask(__name__) # pylint: disable=invalid-name # Set the Flask debug to false so you can use GAE debug app.config.update(DEBUG=False) app.secret_key = Settings.get('SECRET_KEY') app.config['RECAPTCHA_USE_SSL'] = False app.config['RECAPTCHA_PUBLIC_KEY'] = Settings.get('RECAPTCHA_PUBLIC_KEY') app.config['RECAPTCHA_PRIVATE_KEY'] = Settings.get('RECAPTCHA_PRIVATE_KEY') app.config['RECAPTCHA_OPTIONS'] = {'theme': 'white'} @app.before_request def enable_local_error_handling(): ''' test of log ''' app.logger.addHandler(logging.StreamHandler()) app.logger.setLevel(logging.INFO) @app.route('/', methods=['GET', 'POST']) def form(): ''' Show the message form for the user to fill in ''' message_form = forms.MessageForm()