def message_sendlater(token, channel_id, message, time_sent): channelDatabase = Load('Channel_database.pkl') userDatabase = Load('User_database.pkl') messageDatabase = Load('Message_database.pkl') timesent = int(time_sent) helper.check_message_length(message) if helper.check_exist(channelDatabase, int(channel_id), 'channelId') == False: error_raise.invalid_channelid() #check if time is in the past elif helper.get_time() < int(timesent): error_raise.time_is_in_past() else: u_id = helper.find_id_from_token(token) for j in range(len(channelDatabase)): if channelDatabase[j]['channelId'] == int(channel_id): if helper.check_exist(channelDatabase[j]['all_members'], u_id, 'u_id') == False: error_raise.unable_to_operate() helper.timerStart(timesent) while helper.timerGoing(): print("still going") time.sleep(2) return message_send(token, channel_id, message)
def resolve_vp(self, info, end_of_w, market_num, start_amount): name = "VP" current_count = helper.get_count(name, end_of_w) time = helper.get_time() market_num, start_amount = helper.get_market_number("VP") print("current count:", current_count) print("current time:", time) yes, no, norm, kde, mean, std, percentage = twitterfetcher.generate_single_price( name, current_count, time, end_of_w, market_num, start_amount) stuff = {} for i in range(0, len(yes)): count = i + 1 stuff.update({"B{}y".format(count): yes[i]}) stuff.update({"B{}n".format(count): no[i]}) stuff.update({"norm": norm}) stuff.update({"kde": kde}) stuff.update({ "count": current_count, "time": time, "mean": mean, "std": std }) stuff.update({"percentage": int(percentage * 100)}) print(stuff) return [stuff]
def resolve_rdt(self, info, end_of_w, market_num, start_amount): current_count = 3 # helper.get_count() time = helper.get_time() name = "realdonaldtrump" yes, no = twitterfetcher.generate_single_price(name, current_count, time, end_of_w, market_num, start_amount) stuff = {} for i in range(0, len(yes)): count = i + 1 stuff.update({"B{}y".format(count): yes[i]}) stuff.update({"B{}n".format(count): no[i]}) print(stuff) return [stuff]
def message_send(token, channel_id, message): channelDatabase = Load('Channel_database.pkl') userDatabase = Load('User_database.pkl') messageDatabase = Load('Message_database.pkl') #check if message is more than 1000 characters helper.check_message_length(message) u_id = helper.find_id_from_token(token) for j in range(len(channelDatabase)): if channelDatabase[j]['channelId'] == int(channel_id): if helper.check_exist(channelDatabase[j]['all_members'], u_id, 'u_id') == True: message_id = helper.create_messageid(int(channel_id), message) print(messageDatabase) #if helper.check_exist(channelDatabase[j]['messagelist'], message_id, 'message_id') == False: #if not any(d['messagelist'] == message_id for d in channelDatabase): if message_id not in channelDatabase[j]['messagelist']: channelDatabase[j]['messagelist'].append(message_id) messageDatabase.append({ 'message_id': message_id, 'u_id': u_id, 'channel_id': channel_id, 'message': message, 'time': helper.get_time(), 'react_id': [{ 'react_id': 1, 'u_ids': [], 'is_this_user_reacted': bool(False) }], 'is_pinned': False }) pickle_users(userDatabase) pickle_channels(channelDatabase) pickle_message(messageDatabase) return {'message_id': message_id} else: error_raise.user_not_in_channel()
def get_random_url(): return "http://www." + get_random_string(6) + ".com" num_users = int(sys.argv[1]) num_stories = int(sys.argv[2]) num_comments = int(sys.argv[3]) thread_cnt = 0 comment_thread_hash = {} short_ids = [] comment_id = 0 comment_id_start = 1 for i in range(0, num_comments): created_at = str(helper.get_time(num_comments - i))[0:-7] updated_at = created_at short_id = get_random_string(6) while short_id in short_ids: short_id = get_random_string(6) short_ids.append(short_id) story_id = str(random.randint(1, num_stories)) user_id = str(random.randint(1, num_users)) comment_id += 1 parent_comment_id = "" thread_id = thread_cnt if i > 10 and random.randint( 1, 10) < 8 and comment_id > comment_id_start + 10: parent_comment_id = random.randint(comment_id_start + 1,
import sys import helper def get_random_string(length): chars = "".join([random.choice(string.letters) for i in xrange(length)]) return chars num_messages = int(sys.argv[1]) num_users = int(sys.argv[2]) short_ids = [] for i in range(0, num_messages): #created_at = str(datetime.datetime.now())[0:-7] created_at = str(helper.get_time(num_messages - i))[0:-7] author_user_id = str(random.randint(1, num_users)) recipient_user_id = str(random.randint(1, num_users)) subject = get_random_string(10) body_length = random.randint(128, 1024) body = get_random_string(body_length) short_id = get_random_string(6) while short_id in short_ids: short_id = get_random_string(6) short_ids.append(short_id) print ",".join([ str(i + 1), author_user_id, body, created_at, recipient_user_id, short_id, subject ])
def update_time(self, time_label): """ Aktualisiert die Zeit in einem Label """ import helper time = helper.get_time() time_label.setText("<h1>" + time + "</h1>")
def get_random_url(): return "http://www." + get_random_string(6) + ".com" num_users = int(sys.argv[1]) num_stories = int(sys.argv[2]) taggings_file = open("taggings.csv", "w") hidden_file = open("hidden.csv", "w") short_ids = [] story_id = 0 hidden_id = 0 for i in range(0, num_stories): created_at = str(helper.get_time(num_stories - i)) user_id = str(random.randint(1, num_users)) url = get_random_url() title = get_random_string(10) description_length = random.randint(16, 1024) description = get_random_string(description_length) short_id = get_random_string(6) while short_id in short_ids: short_id = get_random_string(6) short_ids.append(short_id) story_id += 1 is_expired = "0" upvotes = str(random.randint(0, 10)) downvotes = str(random.randint(0, 10)) is_moderated = "0" hotness = str(random.uniform(-100, 100))