For this week’s homework in Reading and Writing Electronic Text, I took two Python programs and rewrote the programs to be functions. Here is the revised sketch for my Corporate Motto mashup program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
import sys import random def get_words_from_file(filename) file1_lines = list() for line in open(filename): line = line.strip() file1_lines.append(line) return file1_lines words_from_file = get_words_from_file("corporatemotto2.txt") def create_slogan(words_from_file) slogan_a = random.choice(words_from_file) slogan_b = random.choice(words_from_file) slogan_a_words = slogan_a.split(" ") slogan_b_words = slogan_b.split(" ") first_part = " ".join(slogan_a_words[:4]) second_part = " ".join(slogan_b_words[2:]) return first_part + " " + second_part |
I also took a program that accesses my Gmail account and returns subject lines and sender information, but the program doesn’t work. I am not sure why, but I also haven’t tried to turn this code into a Python program before (I ran this code in Terminal prior).
|
import gmail import datetime def get_messages_from_gmail(): g = gmail.login('username', 'password') g.mailbox('ITP').mail() messages = g.mailbox('ITP').mail(prefetch=True) for message in messages: return message.subject + ", " + message.fr + ", " + message.thread_id |
What I would like to work on next is taking the output made by the Corporate Motto Mashup Program and write a method that automatically feeds the output back into the program.