[Tutor] Facebook login using python
I am working on a program which is used to login to facebook, get my friend lists using graph api and export them into pdf format. So far i'm able to login with facebook and get the friend list. I would like if someone is able to provide me a code to export the output to pdf. Another thing is that i'm hardcoding username, password and access tokens; is there anyway this can be obtained using user input? Code: import urllib2, cookielib, re, os, sys from facepy import GraphAPI class Facebook(): def __init__(self, email, password): self.email = email self.password = password cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) opener.addheaders = [('Referer', 'http://login.facebook.com/login.php'), ('Content-Type', 'application/x-www-form-urlencoded'), ('User-Agent', 'Mozilla/8.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 (.NET CLR 3.5.30729)')] self.opener = opener def login(self): url = 'https://login.facebook.com/login.php?login_attempt=1' data = "locale=en_US&non_com_login=&email="+self.email+"&pass="+self.password+"&lsd=20TOl" usock = self.opener.open('http://www.facebook.com') usock = self.opener.open(url, data) if "Logout" in usock.read(): print "Logged in." else: print "failed login" print usock.read() sys.exit() f = Facebook("Enter email", "Password") f.login() graph=GraphAPI('Enter Access code from fql in developer's page') nik=graph.fql('select uid, name, friends from user where uid in (select first_name, middle_name, last_name from friend where uid1 = me())') print nik ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to create a GUI for python using tkinter
I have attached a python program with this mail which peforms following operations: 1.Logs in to facebook. 2.Asks the user for access tokens. 3.Gets the friend list of the user. 4.outputs the friend list as pdf. My Problems regarding the above program are: 1.I want to display the names of my friends(in output) one in each line in the intermediate .doc file that i have created. example output: {'data': [{'name': 'Roy Fernandes'}, {'name': 'Aniruddh Beigh'}, I want it to be displayed as : Roy Fernandes Aniruddh Beigh 2.Is there a way to automate getting access tokens for the user that is logging in? If not how to get access tokens for each user while logging in? 3.How to dislpay text with clickable links. Eg: Something thing like alert box, wherein if you click the link you go to the page. 4. Finally my lecturer has asked me to create a gui for the facebook login program using tkinter library module. I don't know how to create one (the lecturer has not thought this topic in class so i'm just clueless here). So if someone can do it and explain me the steps it will be very helpfull. newfb.py Description: Binary data ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Performing an union of two files containing keywords
I have 2 different text files. File1.txt contains: file RAMPython parser File2.txt contains: file1234 program I want to perform an union of these both files such that i get an output file3.txt which contains: file RAMPython parser1234 program The program that i'm working on just combines two files. Any help on performing an union such that a keyword would not be repeated would be appreciated. Code: with open("C:\\File1.txt") as fin1: lines = fin1.readlines() with open("C:\\File2.txt") as fin2: lines.extend(fin2.readlines()) with open("D:\\file3.txt", "r+") as fout: fout.write('\n'.join(lines)) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Library for .ppt to .txt conversion
Like pypdf is used to convert pdf to text; is there any library that is used in converting .ppt files to .txt? Even some sample programs will be helpful. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Library for .ppt to .txt conversion
The only thing i want from the ppt's is text and ignoring all graphical representations. I need the text to perform various nltk operations. On Fri, May 30, 2014 at 11:54 PM, Alan Gauld wrote: > On 30/05/14 10:41, Aaron Misquith wrote: > >> Like pypdf is used to convert pdf to text; is there any library that is >> used in converting .ppt files to .txt? Even some sample programs will be >> helpful. >> > > Bearing in mind that Powerpoint is intended for graphical presentations > the text elements are not necessarily going to be useful. Often Powerpoint > text is actually part of a graphic anyway. > > If the Powerpoint is just a set of bullet points (shame on the presenter!) > you probably don't want the text unless you can > also get the notes. I don't know of any libraries that can do that. > > But one option is that Open/Libre office can import Powerpoint and > apparently has a Python API which you could use to drive an export > from there. Just a thought... > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.flickr.com/photos/alangauldphotos > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Unicode Encode Error
I'm trying to obtain the questions present in StackOverflow for a particular tag. Whenever I try to run the program i get this *error:* Message File Name Line Position Traceback C:\Users\Aaron\Desktop\question.py 20 UnicodeEncodeError: 'ascii' codec can't encode character u'\u201c' in position 34: ordinal not in range(128) *This is the code:* import stackexchange import sys sys.path.append('.') so = stackexchange.Site(stackexchange.StackOverflow) term= raw_input("Enter the keyword") print 'Searching for %s...' % term, sys.stdout.flush() qs = so.search(intitle=term) for q in qs: print '%8d %s' % (q.id, q.title) with open('D:\ques.txt', 'a+') as question: question.write(q.title) Can anyone explain me what is going wrong here? This program used to run perfectly fine before. Only since yesterday I have started getting this error. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Python program to search videos using Bing
I have been trying to search videos using bing search engine. But every-time I try I get error HTTPError:HTTPError 403:Forbidden This is the code i am using: import urllib import urllib2 import json def main(): query = "'pyscripter'" print bing_search(query, 'Video') def bing_search(query, search_type): #search_type: Web, Image, News, Video key= 'LsE7jElMmTDfbrnCEmrCmCEBbaPxMG5BvKr9CsfmSNS' query = urllib.quote(query) #create credential for authentication user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; FDM; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 1.1.4322)' credentials = (':%s' % key).encode('base64')[:-1] auth = 'Basic %s' % credentials url = 'https://api.datamarket.azure.com/Data.ashx/Bing/Search/'+search_type+'?Query=%27'+query+'%27&$top=5&$format=json' request = urllib2.Request(url) request.add_header('Authorization', auth) request.add_header('User-Agent', user_agent) request_opener = urllib2.build_opener() response = request_opener.open(request) response_data = response.read() json_result = json.loads(response_data) result_list = json_result['d']['results'] print result_list return result_list if __name__ == '__main__': main() The error shown is: Traceback (most recent call last): File "", line 30, in File "", line 7, in main File "", line 22, in bing_search File "C:\Python27\lib\urllib2.py", line 410, in open response = meth(req, response) File "C:\Python27\lib\urllib2.py", line 523, in http_response 'http', request, response, code, msg, hdrs) File "C:\Python27\lib\urllib2.py", line 448, in error return self._call_chain(*args) File "C:\Python27\lib\urllib2.py", line 382, in _call_chain result = func(*args) File "C:\Python27\lib\urllib2.py", line 531, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) HTTPError: HTTP Error 403: Forbidden Before trying this I worked with YouTube search API which worked fine. But the only problem was that it was limited to the videos present in YouTube database. What I want is the list of URL's of all the videos related to the keyword present in internet. So I started with Bing search engine. Any help regarding this would be appreciated. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor