def post(conf, dir): file_type = conf.get_file_types() max_size = conf.get_max_size() pic_last = conf.get_old_pic() today = datetime.datetime.now().strftime("%A") # load files into a list files = os.listdir(dir) # shuffle the list random.shuffle(files) # try popping until one is found try: pic = os.path.join(dir, files.pop()) while (pic == pic_last) or get_size(pic, max_size) or (not pic.endswith(file_type)): pic = os.path.join(dir, files.pop()) # exit if non are found except IndexError: conf.error('No suitable picture found.') try: status = random.choice(conf.get_status_day(today)) except IndexError: conf.error('No statuses set for ' + today + '.') logging.debug('Posting: ' + pic) p = [pic, status] tweet.tweet_with_pic(conf, p) return
def post(conf, dir): file_type = conf.get_file_types() max_size = conf.get_max_size() pic_last = conf.get_old_pic() today = datetime.datetime.now().strftime("%A") # load files into a list files = os.listdir(dir) # shuffle the list random.shuffle(files) # try popping until one is found try: pic = os.path.join(dir, files.pop()) while (pic == pic_last) or get_size( pic, max_size) or (not pic.endswith(file_type)): pic = os.path.join(dir, files.pop()) # exit if non are found except IndexError: conf.error('No suitable picture found.') try: status = random.choice(conf.get_status_day(today)) except IndexError: conf.error('No statuses set for ' + today + '.') logging.debug('Posting: ' + pic) p = [pic, status] tweet.tweet_with_pic(conf, p) return
def post(conf, dir): width, height = 1024, 512 update = random.choice(conf.get_word()) word = update[0] status = update[1] fontSize = 10 ttf = random.choice(conf.get_font()) colour = random.choice(conf.get_word_colour()) wordColour = colour[0] bgColour = colour[1] # create the image try: pic = Image.new("RGB", (width, height), bgColour) except ValueError: conf.error('Invalid background colour.') draw = ImageDraw.Draw(pic) try: font = ImageFont.truetype(ttf, fontSize) except OSError: conf.error('Invalid font file.') w, h = font.getsize(word) # scale the word while w < width-(width*0.2) and h < height-(height*0.15): font = ImageFont.truetype(ttf, fontSize) w, h = font.getsize(word) fontSize += 1 fontSize -= 1 # create the image try: draw.text(((width-w)/2, (height-h)/2), word, font=font, fill=wordColour) except ValueError: conf.error('Invalid text colour.') logging.debug('Created the picture at: ' + os.path.join(dir, 'pic.png')) logging.debug('Make a copy now if you wish to keep it.') pic.save(os.path.join(dir, 'pic.png')) p = [os.path.join(dir, 'pic.png'), status] tweet.tweet_with_pic(conf, p) return