Beispiel #1
0
def init_db():
    """Create database tables defined by DB_SCHEMA

    Warning: This function will not update existing table definitions
    """
    settings = {}
    settings['db'] = secrets.get_credentials()
    with closing(connect_db(settings)) as db:
        # db.cursor().execute(DB_SCHEMA)
        db.cursor().execute(DB_LOCALS_SCHEMA)
        db.cursor().execute(DB_TWEETS_SCHEMA)
        db.commit()
Beispiel #2
0
def init_db():
    """Create database tables defined by DB_SCHEMA

    Warning: This function will not update existing table definitions
    """
    settings = {}
    settings['db'] = secrets.get_credentials()
    with closing(connect_db(settings)) as db:
        # db.cursor().execute(DB_SCHEMA)
        db.cursor().execute(DB_LOCALS_SCHEMA)
        db.cursor().execute(DB_TWEETS_SCHEMA)
        db.commit()
Beispiel #3
0
def setup_data_snapshot():
    """
    Set up database for interaction.
    """
    settings = {}
    settings['db'] = secrets.get_credentials()
    with closing(connect_db(settings)) as db:
        # cursor = db.cursor()
        # Write venues to locals table
        # venue, screen_name, address, lat, long
        # json.loads(response.content, response.encoding)['results'][0]['geometry']['location']['lat']
        venue_list = []

        venue_list.append(('Key Arena', 'KeyArenaSeattle',
                           '305 Harrison Street, Seattle, WA 98109'))

        venue_list.append(('Neumos', 'Neumos',
                           '925 East Pike Street, Seattle, WA 98122'))

        venue_list.append(('Paramount Theatre', 'BroadwaySeattle',
                           '911 Pine Street, Seattle, WA 98101'))

        venue_list.append(('Fremont Brewing', 'fremontbrewing',
                           '1050 North 34th Street, Seattle, WA 98103'))

        venue_list.append(('Tractor Tavern', 'tractortavern',
                           '5213 Ballard Avenue Northwest, Seattle, WA 98107'))

        venue_list.append(('Nectar Lounge', 'NectarLounge',
                           '412 North 36th Street, Seattle, WA 98103'))

        venue_list.append(('The Triple Door', 'TheTripleDoor',
                           '216 Union Street, Seattle, WA 98101'))

        venue_list.append(('The Showbox', 'ShowboxPresents',
                           '1426 1st Avenue, Seattle, WA 98101'))

        venue_list.append(('The Crocodile', 'thecrocodile',
                           '2200 2nd Avenue, Seattle, WA 98121'))

        venue_list.append(('Central Cinema', 'CentralCinema',
                           '1411 21st Avenue, Seattle, WA 98122'))

        for venue in venue_list:
            write_local(venue, db)


        # Write tweets to tweets table
        # parent_id, author_handle, content, time, count
        for venue in venue_list:
            pull_tweets(venue[1], db)
Beispiel #4
0
def setup_data_snapshot():
    """
    Set up database for interaction.
    """
    settings = {}
    settings['db'] = secrets.get_credentials()
    with closing(connect_db(settings)) as db:
        # cursor = db.cursor()
        # Write venues to locals table
        # venue, screen_name, address, lat, long
        # json.loads(response.content, response.encoding)['results'][0]['geometry']['location']['lat']
        venue_list = []

        venue_list.append(('Key Arena', 'KeyArenaSeattle',
                           '305 Harrison Street, Seattle, WA 98109'))

        venue_list.append(
            ('Neumos', 'Neumos', '925 East Pike Street, Seattle, WA 98122'))

        venue_list.append(('Paramount Theatre', 'BroadwaySeattle',
                           '911 Pine Street, Seattle, WA 98101'))

        venue_list.append(('Fremont Brewing', 'fremontbrewing',
                           '1050 North 34th Street, Seattle, WA 98103'))

        venue_list.append(('Tractor Tavern', 'tractortavern',
                           '5213 Ballard Avenue Northwest, Seattle, WA 98107'))

        venue_list.append(('Nectar Lounge', 'NectarLounge',
                           '412 North 36th Street, Seattle, WA 98103'))

        venue_list.append(('The Triple Door', 'TheTripleDoor',
                           '216 Union Street, Seattle, WA 98101'))

        venue_list.append(('The Showbox', 'ShowboxPresents',
                           '1426 1st Avenue, Seattle, WA 98101'))

        venue_list.append(('The Crocodile', 'thecrocodile',
                           '2200 2nd Avenue, Seattle, WA 98121'))

        venue_list.append(('Central Cinema', 'CentralCinema',
                           '1411 21st Avenue, Seattle, WA 98122'))

        for venue in venue_list:
            write_local(venue, db)

        # Write tweets to tweets table
        # parent_id, author_handle, content, time, count
        for venue in venue_list:
            pull_tweets(venue[1], db)
Beispiel #5
0
def main():
    """Create a configured wsgi app"""
    settings = {}
    settings['reload_all'] = os.environ.get('DEBUG', True)
    settings['debug_all'] = os.environ.get('DEBUG', True)
    settings['db'] = secrets.get_credentials()
    # secret value for session signing:
    secret = os.environ.get('JOURNAL_SESSION_SECRET', 'itsaseekrit')
    session_factory = SignedCookieSessionFactory(secret)
    # configuration setup
    config = Configurator(settings=settings, session_factory=session_factory)
    config.include('pyramid_jinja2')
    config.add_route('home', '/')
    config.add_route('gettweets', '/gettweets')
    config.add_route('writelocation', '/writelocation')
    config.add_static_view('static', os.path.join(here, 'static'))
    config.scan()
    app = config.make_wsgi_app()
    return app
Beispiel #6
0
def validate_and_reload_batch(key, cards, amount):
    if (
        amount <= 0
        or len(cards) == 0
        or False in [card in get_card_names() for card in cards]
    ):
        raise BadRequest()
    try:
        return reload_batch(
            get_credentials(key),
            {
                name: number
                for (name, number) in get_cards(key).items()
                if name in cards
            },
            amount,
        )
    except SecurityException:
        # Block for 5 seconds to mitigate brute-force key attacks.
        sleep(5)
        raise BadRequest()
Beispiel #7
0
def main():
    """Create a configured wsgi app"""
    settings = {}
    settings['reload_all'] = os.environ.get('DEBUG', True)
    settings['debug_all'] = os.environ.get('DEBUG', True)
    settings['db'] = secrets.get_credentials()
    # secret value for session signing:
    secret = os.environ.get('JOURNAL_SESSION_SECRET', 'itsaseekrit')
    session_factory = SignedCookieSessionFactory(secret)
    # configuration setup
    config = Configurator(
        settings=settings,
        session_factory=session_factory
    )
    config.include('pyramid_jinja2')
    config.add_route('home', '/')
    config.add_route('gettweets', '/gettweets')
    config.add_route('writelocation', '/writelocation')
    config.add_static_view('static', os.path.join(here, 'static'))
    config.scan()
    app = config.make_wsgi_app()
    return app
import twitterbot as tb
import secrets
import sys

hashtag = sys.argv[1]

credintials = secrets.get_credentials()

bot = tb.Twitterbot(credintials['email'], credintials['password'])
bot.login()
bot.like_retweet(hashtag)