-
-
Save jjrh/6627441 to your computer and use it in GitHub Desktop.
- Implemented copy to clipboard for the trending stuff. - clicking buttons now also opens the link in your browser.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2, re, time | |
from Tkinter import * | |
import datetime | |
import webbrowser | |
class App: | |
def __init__(self, master): | |
self.master = master | |
frame = Frame(master, bg="") | |
frame.pack() | |
self.buttons = [] | |
for i in range(10): | |
b = Button(self.master,text="",width=32) | |
b.bind("<Button-1>",self.trend_click) | |
self.buttons.append(b) | |
b.pack() | |
self.trend_string = StringVar() | |
self.trend_string.set('') | |
self.trend_dict = {} | |
self.update_string = StringVar() | |
self.update_string.set('Last Updated: ') | |
Label(frame, text='Google+ Trends', | |
font=('Times', '14', 'bold')).grid(row=0, column=0, | |
pady=10, padx=20) | |
Label(frame, textvariable=self.trend_string, | |
justify=LEFT).grid(row=1, column=0,pady=5, padx=20) | |
self.task_bar = Label(frame, bg='white', textvariable=self.update_string, | |
height=1, width=25, anchor=W) | |
self.task_bar.grid(row=2, column=0, sticky=EW) | |
self.trend_loop() | |
def trend_click(self,event): | |
trend=str(event.widget.cget("text")) | |
trend = trend.replace("#","%23") | |
trend = trend.replace(" ","%20") | |
url= "https://plus.google.com/s/"+ trend | |
global root | |
root.clipboard_clear() | |
root.clipboard_append(url) | |
webbrowser.open(url) | |
def trend_loop(self): | |
trend_list = self.get_plus_trends() | |
temp_string = '' | |
dict_list = [x for x in self.trend_dict.keys()] | |
button_list = [] | |
index = 0 | |
for trend in trend_list: | |
self.buttons[index].configure(text=trend) | |
index+=1 | |
self.master.after(6000, self.trend_loop) | |
self.update_string.set('Last Updated: %s' % time.strftime('%H:%M:%S', time.localtime())) | |
def get_plus_trends(self): | |
''' | |
Returns a list of the top 10 trends on Google Plus | |
''' | |
site_file = urllib2.urlopen('https://plus.google.com/s/a') | |
site_raw = site_file.read() | |
a_list = re.findall('s/(\S*)/posts', site_raw) | |
a_list = [urllib2.unquote(x) for x in a_list[:10]] | |
return a_list | |
if __name__ == '__main__': | |
root = Tk() | |
app = App(root) | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment