def main(): local_tz = time.timezone / (60 * 60) current_hour = (datetime.now().hour + (7 + local_tz)) % 24 # to GMT +7 if 0 < current_hour < 5: print 'too late to tweet' return api = setup_api(consumer_key, consumer_secret, access_key, access_secret) dbconn = DBConn() post_table = 'tw' id_column = 'id' name_column = 'tweet' q_num_post = 'SELECT COUNT(*) FROM ' + post_table #calculate the total of rows data in the table num_post = dbconn.read(q_num_post) numb_post = num_post[0][0] #print num_post[0][0] query = 'SELECT ' + id_column + ',' + name_column + ' FROM ' + post_table #query for selecting the data tweet in the table a = dbconn.read(query) rand_number = randint(0, numb_post) #generate random number for randoming the data id_status = str(a[rand_number][0]) status = str(a[rand_number][1]) print id_status, status api.update_status(status) #for update status (tweet) query_delete = 'DELETE FROM ' + post_table + ' WHERE ' + id_column + ' = ' + id_status #query for deleting the data tweet in the table after updated ex = dbconn.delete(query_delete) print ex
def get_link(): dbconn = DBConn() post_table = 'qa_posts' post_id_column = 'postid' title_column = 'title' num_post = 10 query = 'SELECT ' + post_id_column + ', ' + title_column + ' FROM ' + \ post_table + ' WHERE ' + title_column + ' is not null ORDER BY ' + \ post_id_column + ' DESC LIMIT ' + str(num_post) a = dbconn.read(query) rand_number = randint(0, num_post) return str(a[rand_number][1]) + ' | Silahkan baca di ' + create_link(a[rand_number][0])
def main(): local_tz = time.timezone / (60 * 60) #autotweet at the working time (indonesia) current_hour = (datetime.now().hour + (7 + local_tz)) % 24 # to GMT +7 if 0 < current_hour < 5: print 'too late to tweet' return api = setup_api(consumer_key, consumer_secret, access_key, access_secret) dbconn = DBConn() post_table = 'tw' #name of table name_column = 'tweet' #name of column q_num_post = 'SELECT COUNT(*) FROM ' + post_table #count the rows of data num_post = dbconn.read(q_num_post) numb_post =num_post[0][0] #get value from count of rows data #print num_post[0][0] #query for select tweets query = 'SELECT ' + name_column + ' FROM ' + post_table a = dbconn.read(query) rand_number = randint(0, numb_post) api.update_status(str(a[rand_number][0]))