コード例 #1
0
ファイル: reddit.py プロジェクト: mikelane/ShowerThoughtBot
    def get_submissions(self, timeframe):
        submission_list = []
        db = DBAdapter(self.dbfile)
        if timeframe == 'all':
            submissions = self.reddit.get_subreddit(
                'showerthoughts').get_top_from_all()
        elif timeframe == 'day':
            submissions = self.reddit.get_subreddit(
                'showerthoughts').get_top_from_day(limit=5)
        else:
            logging.debug("Invalid timeframe")
            return

        for submission in submissions:
            text = submission.title
            author = '/u/' + submission.author.name
            date = submission.created_utc
            link = submission.short_link
            id = submission.id
            submission_list.append((None, text, author, date, link, id, 0))

        logging.debug("Inserting " + str(len(submission_list)) + " thoughts into the database")
        db.insert_thoughts(submission_list)
コード例 #2
0
 def print_shower_thought(self, chan, nick):
     # #self.db_lock.acquire()
     db = DBAdapter(self.dbfile)
     thought = db.get_random_thought()
     self.send_message(chan, "okay {}: \"{}\" -{}\r\n".format(
         nick, thought[1], thought[2]))
コード例 #3
0
from glob import glob

import colortransfer
from flask import Flask, render_template, session, redirect, url_for, request, flash
from flask_uploads import UploadSet, configure_uploads, IMAGES, patch_request_class
from flask_wtf import FlaskForm
from flask_wtf.file import FileField, FileRequired, FileAllowed
from wtforms import SubmitField, Form, StringField, PasswordField, validators

from dbadapter import DBAdapter

app = Flask(__name__)
app.config['SECRET_KEY'] = 'I have a dream'
app.config['UPLOADED_PHOTOS_DEST'] = os.getcwd()
db_filename = 'users.db'
db = DBAdapter(db_filename)

photos = UploadSet('photos', IMAGES)
configure_uploads(app, photos)
patch_request_class(app)  # set maximum file size, default is 16MB


class RegistrationForm(Form):
    username = StringField('Username', [validators.Length(min=4, max=25)])
    password = PasswordField('New Password', [
        validators.DataRequired(),
        validators.EqualTo('confirm', message='Passwords must match')
    ])
    confirm = PasswordField('Repeat Password')