def add_two_posts(): if db.all_posts(): print("test data exists, no inserts...") return db.insert_post({ 'name': 'Getting started with TinyDB', 'created': str(datetime.datetime(year=2016, month=5, day=1)), 'comments': [] }) db.insert_post({ 'name': 'Smallish embedded databases', 'created': str(datetime.datetime(year=2016, month=6, day=2)), 'comments': [] })
def create_post(self): boardname = "" title = "" content = "" argc = len(self.argv) status = 0 for arg in self.argv: if 0 == status: status = 1 elif 1 == status: if arg == "--title": status = 2 else: boardname = arg elif 2 == status: if arg == "--content": status = 3 else: title = arg if title == "" else title + " " + arg elif 3 == status: content = arg if content == "" else content + " " + arg content = content.replace("<br>", "\r\n") if status != 3 or boardname == "": return self.usage() elif db.insert_post(boardname, self.username, title, content) == 0: return "Create post successfully." else: return "Board does not exist."
def create_post(self): boardname = "" title = "" content = "" argc = len(self.argv) status = 0 for arg in self.argv: if 0 == status: status = 1 elif 1 == status: if arg == "--title": status = 2 else: boardname = arg elif 2 == status: if arg == "--content": status = 3 else: title = arg if title == "" else title + " " + arg elif 3 == status: content = arg if content == "" else content + " " + arg content = content.replace("<br>", "\n") object_name = 'post' + str(int(time.time())) + ''.join(random.choice(string.ascii_lowercase) for i in range(8)) + '.txt' comment_object_name = 'comment' + str(int(time.time())) + ''.join(random.choice(string.ascii_lowercase) for i in range(8)) + '.txt' if status != 3 or boardname == "": return self.usage() elif db.insert_post(boardname, self.username, title, object_name, comment_object_name) == 0: return '&<!create-post::>' + self.bucket + '&<!spl>' + object_name + '&<!spl>' + content + '&<!spl>' + comment_object_name + "&<!meta|msg>Create post successfully." else: return "Board does not exist."
def create_post(self): boardname = "" title = "" content = "" argc = len(self.argv) status = 0 for arg in self.argv: if 0 == status: status = 1 elif 1 == status: if arg == "--title": status = 2 else: boardname = arg elif 2 == status: if arg == "--content": status = 3 else: title = arg if title == "" else title + " " + arg elif 3 == status: content = arg if content == "" else content + " " + arg content = content.replace("<br>", "\n") object_name = 'post' + str(int(time.time())) + ''.join( random.choice(string.ascii_lowercase) for i in range(8)) + '.txt' comment_object_name = 'comment' + str(int(time.time())) + ''.join( random.choice(string.ascii_lowercase) for i in range(8)) + '.txt' if status != 3 or boardname == "": return self.usage() elif db.insert_post(boardname, self.username, title, object_name, comment_object_name) == 0: producer = KafkaProducer(bootstrap_servers=['localhost:9092']) future = producer.send('._-board-' + boardname, key=title.encode(), value=(boardname + '&<!spl>' + self.username).encode()) future = producer.send('._-author-' + self.username, key=title.encode(), value=(boardname + '&<!spl>' + self.username).encode()) return '&<!create-post::>' + self.bucket + '&<!spl>' + object_name + '&<!spl>' + content + '&<!spl>' + comment_object_name + "&<!meta|msg>Create post successfully." else: return "Board does not exist."
for digest_channel in digest_channels: for feed in feeds: if feed["name"] == digest_channel: if len(feed["text"]) > 0: bot.broadcast_message(int(chat[1]), str(config.get("report")) + ":\n" + feed["text"]) bot = Bot() parser = RSSParser() if parse_type =="rss" else VKParser() channels = config.get("channels"); # FLOW for channel in channels: parser.parse(channel['url']) for post in parser.parsed_posts: if is_post_exist(post['id']) == False: insert_post(post, channel['name']) bot.broadcast_post(post, channel['name']) # DAILY current_date = datetime.datetime.fromtimestamp(time.time()) digest_date = get_digest_date()[0] if (current_date > digest_date): posts = get_posts_between_dates(digest_date - timedelta(hours=24), digest_date) chats = get_daily_chats() broadcast_digest(posts, chats) digest_date = digest_date + timedelta(hours=24) set_digest_date(digest_date, "daily") # HOURLY current_date = datetime.datetime.fromtimestamp(time.time())
def send_posts(self, posts): for post in posts: if insert_post(post) == True: self.send_message_all(post["text"]) time.sleep(5)
def fetch_new_posts(): print("Fetching new posts.", time.time()) for post in r_all.new(): if not db.get_post(post.id): db.insert_post(post)
def new_post(thread_id): if request.method == 'POST': forum_id = query_db('SELECT forum FROM threads WHERE id = ?', [thread_id], one=True)['forum'] insert_post(forum_id, thread_id, request.form['message'], session['user_id']) return redirect(url_for('view_thread', thread_id=thread_id)) return render_template('new_post.html', thread_id=thread_id)
def insert_post(author, title, body, date_x): pid = db.insert_post(author, title, body, date_x); cp.put(pid, (pid, author, title, body, date_x)); return pid;
def insert_post(author, title, body, date_x): pid = db.insert_post(author, title, body, date_x) cp.put(pid, (pid, author, title, body, date_x)) return pid