def getnews(): user = request.form['user'] if (user == ''): return render_template('news.html', posts=database.get_posts(0, 10)) return render_template('news.html', posts=database.get_posts_by_creator(0, 10, user))
async def posts(tags: str = ''): selected_tags = get_tags_from_string(tags) if tags else None posts_results = get_posts(selected_tags).all() return PostsResponse(meta=PostsResponseMeta( count=len(posts_results), selected_tags=selected_tags if selected_tags else SelectedTags()), posts=posts_results)
def posts(): if request.method == 'POST': if current_user.is_authenticated: db.insert_post(current_user.username, request.form['message']) else: flash('You must be logged in to post!') posts_list = db.get_posts() args = {'active': 'posts', 'posts': posts_list} return render_template('posts.html', args=args)
def main(): url = 'http://vg.no' keywords = ['snegl', 'kropp', 'dette', 'paradise', 'pladask', 'miss universe', 'frøken norge', 'sex', 'triks', 'pokemon', 'undertøy', 'hollywood', 'kjendis', 'øvelse', 'slik', 'slank', 'digg' ] old_posts = database.get_posts() try: new_posts = crawler.crawl(url, keywords) new = 0 for k,v in new_posts.items(): if k not in old_posts.keys(): title = v['title'].encode('utf-8') print 'POSTING' , title print twitter.post_status(title) database.add_post(k, v) new += 1 time.sleep(1) if new == 0: print 'no new posts found' elif new == 1: print 'one new post found' else: print str(new) + ' new posts found' except requests.exceptions.ConnectionError: print 'could not connect'
def hour_job(): time = int(datetime.strftime(datetime.now(tz=pytz.timezone('Europe/Moscow')), "%H")) posts = database.get_posts(time) if posts: for post in posts: post = list(post) if post[2]: if "voice" in post[2]: bot.send_voice(chat_id=post[5], file_id=post[2][5:]) else: if post[1] == "": bot.send_file(chat_id=post[5], file_id=post[2]) else: bot.send_file(chat_id=post[5], caption=post[1], file_id=post[2]) else: bot.send_text(chat_id=post[5], text=post[1]) database.update_post(post[0])
def main(): #get the needed posts from the database conn = sqlite3.connect('miiverse-small.db') cur = conn.cursor() posts = database.get_posts(cur) #load the twitter api auth = tweepy.OAuthHandler(secrets.API_KEY, secrets.API_SECRET_KEY) auth.set_access_token(secrets.ACCESS_TOKEN, secrets.ACCESS_SECRET) api = tweepy.API(auth) #wait for the first interval (12a, 4a, 8a, etc. in EST) currentHour = datetime.now().replace(second=0, microsecond=0, minute=0) currentHour += timedelta(hours=1) while currentHour.hour % 4 != 0: currentHour += timedelta(hours=1) print((currentHour - datetime.now()).total_seconds()) time.sleep((currentHour - datetime.now()).total_seconds()) #for every post, get the needed data, format it into a tweet, #update the database to reflect the posting, and then wait 4 hours while len(posts) > 0: start = time.time() post = posts.pop(0) postedDrawing = None while postedDrawing == None: body = compose.create_tweet_text(post) try: postedDrawing = drawing.get_drawing(post[2]) except: print(post[2], "not found!") print(body) postedDrawing.save("drawing.png") api.update_with_media("drawing.png", status=body) cur.execute("UPDATE Posts SET Posted=1 WHERE Id='"+post[0]+"'") conn.commit() print(post[2]) end = time.time() durationTime = end - start print(14400 - durationTime) time.sleep(14400 - durationTime) conn.close()
def index(lang="en/"): posts = database.get_posts(0, 10) posts_and_users = [(post[0:5], post[5]) for post in posts] return render_page("index.html", lang, posts_and_users=posts_and_users)
def get_posts(): return jsonify(db.get_posts())