コード例 #1
0
def process_submission(reddit, submission):
    print('Processing new submission: ' + submission.title)
    already_commented = False
    author = submission.author

    if hour_difference(submission.created_utc, time.time()) >= MAX_TIME:
        print('Old post, ignoring')
        return

    if submission.removed:
        print('Violates rules, ignoring')
        return

    for comment in submission.comments:
        if USERNAME == comment.author:
            already_commented = True

    if not already_commented:
        first_response = get_response(FIRST_RESPONSE_CODE)
        reddit.redditor(author.name).message(submission.url,
                                             first_response.comment)
        db.add_entry(submission.id.lower(), submission.url.lower(),
                     author.name.lower(), FIRST_RESPONSE_CODE)
        print('Messaged author of new post')
        submission.mod.remove()

    print('Processed Successfully')
コード例 #2
0
ファイル: functionality.py プロジェクト: Admetty/project_A
def make_an_entry(data):
    entry = input('Write about the book, [x] to exit: \n')

    if entry == 'x':
        return

    db.add_entry(entry, data)
コード例 #3
0
ファイル: widgets.py プロジェクト: robdelacruz/boneyard
        def on_save_clicked(w):
            entry = self.get_entry()
            db.add_entry(self._con, entry)
            db.commit(self._con)
            self.clear()

            if self.on_save:
                self.on_save(entry)
コード例 #4
0
ファイル: blog.py プロジェクト: kuma275m/Blog_Exercise
def add():
    is_login()
    if request.method == 'POST':
	title = request.form['title']
	content = request.form['content']
	tags = request.form['tags']
	db.add_entry(title, content, tags)
	return redirect(url_for('index'))
    return render_template('add.html')
コード例 #5
0
ファイル: generate_feed.py プロジェクト: dark-nova/twitch_rss
def get_loot(loot, category: str) -> ENTRIES:
    """Gets loot for a given `loot` type.

    Called by `get_all_loot`.

    Args:
        fg (FeedGenerator): the feed to add entries
        loot: bs4 object; the loot to parse
        category (str): either 'In-Game Loot and More'
            or 'Games with Prime'

    Returns:
        dict: {title: (description, category, link, pub_date)}

    """
    today = pendulum.today(tz='UTC')

    entries = {}

    for offer in loot.find_all('div', 'offer'):
        description = []

        info = offer.find('div', 'offer__body__titles')
        title = info.find('p', 'tw-amazon-ember-bold').text.strip()

        offered_by = info.find('p', 'tw-c-text-alt-2').text.strip()
        description.append(f'Offered by: {offered_by}')

        claim_info = offer.find('div', 'claim-info')
        expires_by = claim_info.find('span', '').text.strip()
        if expires_by == 'Offer ends soon':
            expires_by = 'soon'
        description.append(f'Expires: {expires_by}')

        try:
            link = offer.find('a')['href']
        except TypeError:
            link = URL
            description.append('Visit main page to claim offer.')

        if db.check_if_entry_exists(title):
            pub_date = db.get_entry_time(title)
        else:
            pub_date = today
            db.add_entry(
                title,
                today
                )

        entries[title] = (
            ' | '.join(description),
            category,
            link,
            pub_date
            )

    return entries
コード例 #6
0
ファイル: signer.py プロジェクト: systemconsole/syco-signer
def add_entry(date):
    try:
        db.add_entry(current_user.username, request.form['sign_message'], date)
        return redirect(url_for('signed'))
    except IntegrityError:
        flash('New entry failed, duplicate entry.', 'flash-error')
    except Exception as e:
        flash('New entry failed.', 'flash-error')

    return redirect(url_for('log_entries', date=date))
コード例 #7
0
ファイル: scraper.py プロジェクト: dark-nova/tos_rss
def get_news():
    # with open('example.html', 'r') as example:
    #     soup = BeautifulSoup(example, 'html.parser')
    page = requests.get('https://treeofsavior.com/page/news/')
    soup = BeautifulSoup(page.text, 'html.parser')

    news = soup.find_all('div', 'news_box')

    all_news = []

    for news_article in news:
        article = {}
        inner = news_article.find('div', 'box_inner')
        article_date = inner.find('div', 'date')
        try:
            article_date = article_date.string.lstrip().split()
            article['url'] = get_article_url(news_article)
            article['title'] = news_article.h3.string
            a_date = convert_article_date(article_date)
            today = pendulum.today()
            if db.check_if_entry_exists(article['url']):
                article['date'] = db.get_entry_time(article['url'])
            else:
                if today == pendulum.datetime(*a_date, tz = today.tz):
                    article['date'] = pendulum.datetime(
                        *a_date,
                        pendulum.now(tz = 'UTC').hour,
                        tz = 'UTC'
                        )
                else:
                    # If the article date doesn't match up with today's date,
                    # do not modify the publish time. Fallback for
                    # migrating setups, or resuming after pausing for some
                    # time.
                    article['date'] = pendulum.datetime(
                        *a_date,
                        0,
                        tz = 'UTC'
                        )
                db.add_entry(
                    article['url'],
                    article['date']
                    )
            all_news.append(article)
        except AttributeError as e:
            logger.warning(
                f'Caught exception {e} from {article}, inner {inner}'
                )

    db.purge_old()

    return all_news
コード例 #8
0
ファイル: phonebook.py プロジェクト: mlauter/hsphonebook
def add(name, number, phonebook):
    from pudb import set_trace; set_trace()
    pb_id = db.get_phonebook_id(phonebook)
    if pb_id:
        status = db.add_entry(pb_id[0], (name, number))
        if status:
            print "%s added to %s with number %s" % (name, phonebook, number)
        else:
            print "Error: name: %s or number: %s already present in %s" % (name,number , phonebook)
    else:
        print "Error: phonebook does not exist"
コード例 #9
0
ファイル: dict.py プロジェクト: rohtang/balkdict
 def POST(self):
     i = web.input()
     if(len(i.word) and len(i.description)):
         print "sanitising strings..."
         word = sanitize(i.word)
         desc = sanitize(i.description)
         if db.add_entry(word, desc) != None:
             return "ah-okay!"
         else:
             return "something went haywire..."
     return "booo..."
コード例 #10
0
ファイル: app.py プロジェクト: rcshubhadeep/digital-diary
def post_entry():
    '''POST data from the form will come here. Notice that we have specified 
    methods (http VERB) which can access this route. If you are running this application
    locally, try hitting http://localhost:5000/post_entry and see what you get'''
    if request.method == 'POST':
        ## Adding the reccord to DB and redirecting with proper flash message
        ret = db.add_entry(user_name=request.form['user_name'],
                        title=request.form['entry_title'],
                 date=request.form['entry_date'], entry=request.form['entry'])
        if ret == True:
            flash('Entry successfully added -- ' + session['name'])
            return redirect(url_for('index'))
        else:
            flash("Opps! Somwthing went wrong!")
            return redirect(url_for('index'))       
コード例 #11
0
def prompt_new_entry():
    content = input("Subject studied today: ")
    entry_date = input("Date: ")
    add_entry(content, entry_date)
コード例 #12
0
ファイル: server_tester.py プロジェクト: jaybcee/BoatsBeGone
 def add_db(self):
     db.add_entry(self.direction, self.start, self.end, self.timeElapsed)