def tweetAppend(tweetnum, branded_True_or_False): """ Append to the JSON object an entry that is {branded: True|False|None}. This can then be read in future iterations so the program skips it. """ data = Twitterate.tweetRead(tweetnum, 'unmarked') data.update({'branded': str(branded_True_or_False)}) with open("output\\marked.json", 'a+') as tweetWrite: json.dump(data, tweetWrite) tweetWrite.write('\n')
def mark_branded(tweetnum): """ Print the tweet text and ask for a decision to mark as branded, unbranded or none. """ tweet_text = repr( Twitterate.tweetRead(tweetnum, 'unmarked')[u'text'].replace("\n", "") )[2:-1] print("%i\t%s" % (tweetnum, tweet_text)) decision = input("Enter 1 to mark as branded, 2 to mark as unbranded, 0 to skip\n") if decision in "120": if decision == "1": tweetAppend(tweetnum, True) elif decision == "2": tweetAppend(tweetnum, False) else: tweetAppend(tweetnum, None) logging.info("\tTweet %i marked %s:\n\t%s\n" % ( tweetnum, ['SKIPPED', 'BRANDED', 'UNBRANDED'][int(decision)], tweet_text) ) else: print(colored('\nInput not recognised!\n', 'red')) # colours are fun mark_branded(tweetnum)