def check_random_list(): """ <Name> check_random_list() <Description> Randomly picks a word from a dictionary and tries to fetch the wikipedia article of a list for it. If there is a list of this word, the word is returned. If there isn't a LOLException is raised. <Raises> LOLException(word): if there isn't a list of this word in wikipedia <Returns> word: the word that *does* contain a list """ # get a random word from our magical wikipedia page randfile = linereader.copen(DICT) random_word = randfile.getline(random.randint(1, WC_DICT)) query = "List of {}".format(random_word) try: page = wikipedia.page(query) except wikipedia.exceptions.PageError: raise LOLException(random_word) result_word = page.title.lstrip("List of") if result_word != random_word: raise LOLException(random_word) return random_word
def _word_chooser(word_count): """Random Word Generator private funtion. Uses the copen function from linereader to have random access to a csv file. Using the numpy random function, a random line is chosen decoded to UTF-8 and placed in a tuple that is appended to a list. Using the word count in each line, the function keeps adding words to the sample list until it the current line puts the word count to or above the target word count. Parameters: word_count(int): target word count Returns: list: list of randomly chosen plant names """ sample_word_count = word_count sample = [] current_words = 0 file = linereader.copen(FILENAME) while current_words < sample_word_count: j = random.randint( 2, LASTROW) #skips the first line as it is the header line data = file.getline(j) for row in csv.reader([data]): sample.append( PlantName(bot=row[0].decode('utf-8').replace("'", ""), com=row[1].decode('utf-8').replace("'", ""), words=row[2])) words = int(row[2]) current_words += words return sample
def word_list(filename): f = copen(filename) lines = f.count("\n") bl = list(range(lines)) random.shuffle(bl) for i in bl: l = f.getline(i) yield l.split('\t')
def random_word(): # credit to https://www.ef.com/wwen/english-resources/english-vocabulary/top-3000-words/ words_list = copen( r"C:\Users\itays\OneDrive\Desktop\Usb-backup\Itay\Python\the_most_commons_words_in_english.txt" ) # credit to https://stackoverflow.com/questions/3540288/how-do-i-read-a-random-line-from-one-file-in-python lines = words_list.count('\n') word = words_list.getline(randint(1, lines)) word = word.split("\n")[0] words_list.close() return word
import tweepy from linereader import copen from random import randint import time #import twitter apps configaration file from config.py file from config import * #Authentication using keys & accesstoken auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth) #Chooses amount of lines from lyrics.py to tweet out to the connected twitter account. lyrics = copen('lyrics.txt') lines = lyrics.count('\n') lastline = 0 while True: gottenline = randint(1, lines) while gottenline == lastline: gottenline = randint(1, lines) tweet_text = lyrics.getline(gottenline) if len(tweet_text) <= 140 and tweet_text != '\n': tweet_text = tweet_text.replace("|", '\n') api.update_status(status=tweet_text) print tweet_text time.sleep(3600)
'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y' ] Qvv = range(len(Qvd))[::-1] QVdict = dict(zip(Qvd, Qvv)) dbname = sys.argv[1] lasname = sys.argv[2] n = int(sys.argv[3]) path = os.getcwd() + '/' coveragename = path + dbname + '.coverage.txt' aln = [] coveragefile = linereader.copen(coveragename) coverage = coveragefile.getline(n) cov = coverage.split()[2:] covx = [] covy = [] for item in cov: data = item.split(',') covx.append(int(data[0])) covy.append(int(data[1])) qv = list(util.get_QV(path + dbname, [n]))[0] qx = [] qy = [] ts = int(sys.argv[5])
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y'] Qvv = range(len(Qvd))[::-1] QVdict = dict(zip(Qvd,Qvv)) dbname = sys.argv[1] lasname = sys.argv[2] n = int(sys.argv[3]) path = os.getcwd()+'/' coveragename = path + dbname + '.coverage.txt' aln = [] coveragefile = linereader.copen(coveragename) coverage = coveragefile.getline(n) cov = coverage.split()[2:] covx = [] covy = [] for item in cov: data = item.split(',') covx.append(int(data[0])) covy.append(int(data[1])) qv = list(util.get_QV(path+dbname, [n]))[0] qx = [] qy = [] ts = int(sys.argv[5])
def send_nope(chan): nopefile = copen(NOPE_FILE) lines = nopefile.count('\n') random_line = nopefile.getline(randint(1, lines)) chan.send(random_line + "\r")
def get_random_dua(): openfile = copen("./responseConstants/dua.txt") lines = openfile.count('\n') + 1 dua = openfile.getline(randint(1, lines)) return dua
def get_random_dua(): openfile = copen("dua.txt") lines = openfile.count('\n') + 1 dua = openfile.getline(randint(1, lines)) return dua
import time, tweepy, os from linereader import copen from random import randint """tweepy doing its magic""" CONSUMER_KEY = os.environ['CKEY'] CONSUMER_SECRET = os.environ['CSECRET'] ACCESS_KEY = os.environ['AKEY'] ACCESS_SECRET = os.environ['ASECRET'] auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(ACCESS_KEY, ACCESS_SECRET) api = tweepy.API(auth) lyrics = copen('frases') lines = lyrics.count('\n') lastline = 0 while True: gottenline = randint(1, lines) while gottenline == lastline: gottenline = randint(1, lines) lastline = gottenline secondsSleeping = randint(3600*3+14*60, 3600*6+28*60) tweet_text = lyrics.getline(gottenline) if len(tweet_text) <= 140 and tweet_text != '\n': api.update_status(status=tweet_text) print tweet_text time.sleep(secondsSleeping)