Merge lp:~joel-auterson/python-snippets/twitter-snippets into lp:~jonobacon/python-snippets/trunk

Proposed by Joel Auterson
Status: Merged
Merged at revision: not available
Proposed branch: lp:~joel-auterson/python-snippets/twitter-snippets
Merge into: lp:~jonobacon/python-snippets/trunk
Diff against target: 77 lines (+72/-0)
1 file modified
twitter/twit.py (+72/-0)
To merge this branch: bzr merge lp:~joel-auterson/python-snippets/twitter-snippets
Reviewer Review Type Date Requested Status
Jono Bacon Pending
Review via email: mp+22730@code.launchpad.net

Description of the change

A twitter snippet, that logs in to the user's account and lets them post a new status.

To post a comment you must log in.
Revision history for this message
Jono Bacon (jonobacon) wrote :

Thanks, Joel! Merged. :-)

Thanks for your fantastic snippet. I made a few small changes:

 * Changed the category to a lower-cased 'twitter' - this is the name of the module. Ultimately I am keen for all snippets to be categorized by module.
 * I also added 'PyGTK' as a category as you use GTK to run the snippet.

Finally, when adding new directories, would be great if you could also update CATEGORIES.

Could you do me one small favor? Could you put a link to the API docs for the twitter Python module in a SNIPPET_DOCS line and propose a new merge?

80. By Jono Bacon <jono@system76-pc>

docstest, twitter and unittest snippets. :-)

Revision history for this message
Joel Auterson (joel-auterson) wrote :

Added the doc. Thanks for tweeting about my snippet! :)

Joel

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'twitter'
2=== added file 'twitter/twit.py'
3--- twitter/twit.py 1970-01-01 00:00:00 +0000
4+++ twitter/twit.py 2010-04-02 22:19:15 +0000
5@@ -0,0 +1,72 @@
6+# [SNIPPET_NAME: Login and Tweet]
7+# [SNIPPET_CATEGORIES: Twitter]
8+# [SNIPPET_DESCRIPTION: Log in to your Twitter account and update your status.]
9+# [SNIPPET_AUTHOR: Joel Auterson joel.auterson@googlemail.com]
10+# [SNIPPET_LICENSE: GPL]
11+
12+import twitter
13+import pygtk
14+import gtk
15+
16+class GTK_Main():
17+
18+ def __init__(self):
19+
20+ def loginClicked(loginButton):
21+
22+ user = loginUserT.get_text()
23+ passwd = loginPassT.get_text()
24+ global api
25+ api = twitter.Api(username=user, password=passwd)
26+ login.hide()
27+ window.show_all()
28+
29+ def twitClicked(twitButton):
30+
31+ newtweet = twitE.get_text()
32+ api.PostUpdate(newtweet)
33+ gtk.main_quit()
34+
35+ #Create things - Login
36+
37+ login = gtk.Window()
38+ login.connect("destroy", gtk.main_quit)
39+ login.set_title("Login")
40+ loginVbox = gtk.VBox(homogeneous=False)
41+ loginLabel = gtk.Label("Please log in to Twitter!")
42+ loginHbox1 = gtk.HBox(homogeneous=False, spacing=3)
43+ loginHbox2 = gtk.HBox(homogeneous=False, spacing=3)
44+ loginUserL = gtk.Label("User:")
45+ loginPassL = gtk.Label("Pass:")
46+ loginUserT = gtk.Entry()
47+ loginPassT = gtk.Entry()
48+ loginButton = gtk.Button(label="Log In")
49+ loginButton.connect("clicked", loginClicked)
50+
51+ login.add(loginVbox)
52+ loginVbox.pack_start(loginLabel, expand=False)
53+ loginVbox.pack_start(loginHbox1, expand=False)
54+ loginVbox.pack_start(loginHbox2, expand=False)
55+ loginVbox.pack_start(loginButton, expand=True)
56+ loginHbox1.pack_start(loginUserL, expand=False)
57+ loginHbox1.pack_start(loginUserT, expand=True)
58+ loginHbox2.pack_start(loginPassL, expand=False)
59+ loginHbox2.pack_start(loginPassT, expand=True)
60+
61+ #Create tweeting window
62+
63+ window = gtk.Window()
64+ window.connect("destroy", gtk.main_quit)
65+ window.set_title("Twitter")
66+ twitvbox = gtk.VBox(homogeneous=False)
67+ twitE = gtk.Entry()
68+ twitButton = gtk.Button(label="Tweet!")
69+ window.add(twitvbox)
70+ twitvbox.pack_start(twitE, expand=False)
71+ twitvbox.pack_start(twitButton, expand=True)
72+ twitButton.connect("clicked", twitClicked)
73+
74+ login.show_all()
75+
76+GTK_Main()
77+gtk.main()

Subscribers

People subscribed via source and target branches