Example #1
0
def front():
    if 'osm_token' in session:
        return front_osm()
    if 'X-Forwarded-For' in request.headers:
        ip = request.headers.getlist("X-Forwarded-For")[0].rpartition(' ')[-1]
    else:
        ip = request.remote_addr or 'unknown'
    task = load_task(random_task_for_ip(ip))
    return render_template('index.html', task=render_task(task))
Example #2
0
def front():
    user = get_user()
    if not user:
        task = ch.load_task(ch.random_task_for_ip(get_ip()), g.lang['tasks'])
        msg = html_esc(g.lang['please_sign_in']).replace(
            '[', '<a href="' + html_esc(url_for('login')) + '">').replace(
                ']', '</a>')
        return render_template('index.html',
                               task=render_task(task),
                               msg=msg,
                               lang=g.lang)

    task_obj = ch.get_or_create_task_for_user(user)
    task = ch.load_task(task_obj.task, g.lang['tasks'])
    return render_template('front.html',
                           task=render_task(task),
                           user=user,
                           tobj=task_obj,
                           lang=g.lang,
                           timeleft=ch.time_until_day_ends(g.lang))
Example #3
0
def front_osm():
    if 'osm_token' not in session:
        redirect(url_for('login'))
    user = get_user()
    task_obj = get_or_create_task_for_user(user)
    task = load_task(task_obj.task)
    return render_template('front.html',
                           task=render_task(task),
                           user=user,
                           tobj=task_obj,
                           timeleft=time_until_day_ends())
Example #4
0
 def _print_task(self):
     tg = self._get_tg()
     task_obj = ch.get_or_create_task_for_user(tg.user)
     if task_obj.changeset:
         self.sender.sendMessage(self.t('task_complete'))
     else:
         task = ch.load_task(task_obj.task, self.lang['tasks'])
         self.sender.sendMessage(u'{} {}\n\n{}\n\n{}: {}\n\n{}'.format(
             task['emoji'], task['t_title'], desc_to_markdown(task),
             self.t('time_left'), ch.time_until_day_ends(self.lang),
             self.t('post_changeset')),
                                 parse_mode='Markdown')
Example #5
0
def send_reminder(bot, hm):
    query = Telegram.select().where(Telegram.remind_on == hm)
    for tg in query:
        lang = load_language(tg.user)
        task_obj = ch.get_or_create_task_for_user(tg.user)
        if task_obj.changeset is not None:
            continue
        task = ch.load_task(task_obj.task, lang['tasks'])
        msg = u'{} {}\n\n{}\n\n{}'.format(
                task['emoji'], task['t_title'], desc_to_markdown(task),
                lang['post_changeset'])
        try:
            bot.sendMessage(tg.channel, msg, parse_mode='Markdown')
        except telepot.exception.TelegramError as e:
            try:
                bot.sendMessage(tg.channel, msg)
                logging.error('Failed to send markdown, but text worked. Task %s, msg: %s',
                              task_obj.task, msg)
            except telepot.exception.TelegramError as e:
                logging.error('Could not remind user %s: %s', tg.user.name, e.description)
Example #6
0
def send_email(user):
    lang = ch.load_language_from_user('', user)
    lang['tasks'] = ch.load_language_from_user('tasks', user)
    task_obj = ch.get_or_create_task_for_user(user)
    task = ch.load_task(task_obj.task, lang['tasks'])
    desc = task['t_description']
    message = u'{hi}\n\n{task}\n\n{emoji} {title}\n\n{desc}\n\n{submit}\n\n{bye}\n{streak}'.format(
        hi=lang['email']['hi'].format(user.name), task=lang['email']['new_task'],
        emoji=task['emoji'], title=task['t_title'], desc=desc,
        submit=lang['email']['to_submit'].format(config.BASE_URL), bye=lang['email']['bye'],
        streak=lang['title']
    )
    msg = MIMEText(message, 'plain', 'utf-8')
    msg['Subject'] = u'[{}] {} {}'.format(lang['title'], task['emoji'], task['title'])
    msg['From'] = formataddr(('OSM Streak', config.EMAIL_FROM))
    msg['To'] = formataddr((user.name, user.email))

    s = smtplib.SMTP('localhost')
    s.sendmail(config.EMAIL_FROM, [user.email], msg.as_string())
    s.quit()
Example #7
0
#!/usr/bin/env python
import config
import os
import ch_util as ch
from ruamel.yaml import YAML

lang = {}
for t in sorted(ch.get_tasks(100)):
    t_name = t.split('_', 1)[1]
    task = ch.load_task(t)
    lang[t_name] = {'title': task['title'], 'description': task['description']}

yaml = YAML()
with open(os.path.join(config.BASE_DIR, 'lang', 'tasks', 'en.yaml'), 'w') as f:
    yaml.dump({'en': lang}, f)