def week_job(): os.system('python get_all_tweets.py') os.system('python get_works.py') ### Post to LINE-Notify post_line_notify('everyweek')
def main(): SN = os.environ.get('SECRET_NAME','') ### Load all tweet from log file with open('out.json', 'r') as f: data = json.load(f) ### Pickup only work tweet all_works = {'id': []} with open('tags.json', 'r') as f: search_tags = json.load(f) for d in data: """Pick up on the condition that... * specific hashtag is attached * not reply for myself * not retweet of other """ hashtags = d['entities']['hashtags'] is_self_reply = d['in_reply_to_screen_name'] == SN is_other_retweet = False if 'retweeted_status' in d: is_other_retweet = not d['retweeted_status']['user']['screen_name'] == SN if len(hashtags) > 0 and (not is_other_retweet) and (not is_self_reply): tag = hashtags[0]['text'] if tag in search_tags: # print('id: ' + d['id_str']) # print('text: \n' + d['full_text']) # print('------') all_works['id'].append(d['id']) # print("------------------------------------") # print("all_works: " + str(len(all_works['id']))) ### Save id list with open('work.json', 'w') as f: json.dump(all_works, f, ensure_ascii=False, indent=4, sort_keys=True, separators=(',', ': ')) ### Post to LINE-Notify post_line_notify('Updated all works file.')
def main(): SN = os.environ.get('SECRET_NAME', '') ### Choice tweet randomly with open('work.json', 'r') as f: data = json.load(f) tar_id = random.choice(data['id']) ### Check target tweet twitter = connect_sess() params = { 'id': tar_id, 'tweet_mode': 'extended', } tweet = get_tweet_info(twitter, params) # print('id: ' + tweet['id_str']) # print('text: ' + tweet['full_text']) # print("------") # print(json.dumps(tweet, sort_keys = True, indent = 4)) ### Unretweet (if already self-retweeted) if tweet['retweeted']: post_unretweet(twitter, {'id': tar_id}) ### Self-retweet post_retweet(twitter, {'id': tar_id}) ### Post to LINE-Notify msg = [ \ 'Retweeted.\n' \ + '------\n' \ + 'id: ' + tweet['id_str'] + '\n' \ + 'test: ' + tweet['full_text'] ] post_line_notify(msg)
def main(): SN = os.environ.get('SECRET_NAME', '') ### First access twitter = connect_sess() params = { 'count': 100, 'screen_name': SN, 'tweet_mode': 'extended', # to get full-text } timelines = get_user_timeline(twitter, params) ### Get all tweet from self timeline all_tweets = [] while len(timelines) > 0: all_tweets = all_tweets + timelines # more get... params['max_id'] = timelines[len(timelines) - 1]['id'] - 1 timelines = get_user_timeline(twitter, params) # print("------------------------------------") # print('all_tweets: ' + str(len(all_tweets))) ### Save with open('out.json', 'w') as f: json.dump(all_tweets, f, ensure_ascii=False, indent=4, sort_keys=True, separators=(',', ': ')) ### Post to LINE-Notify post_line_notify('Updated all tweet file.')
def day_job(): os.system('python post_self_retweet.py') ### Post to LINE-Notify post_line_notify('everyday')