Commit bd070d929998cc886a43a5fa536b3f89a3c293a8
Generate access token based on app_secret and app_id. Adding sampleConf.py,
this contains the keys for app_secret, app_id and username.
| | | | 7 | lib/ | 7 | lib/ |
---|
8 | *.db | 8 | *.db |
---|
9 | *.pid | 9 | *.pid |
---|
| | 10 | conf.py |
---|
| | | | | | 1 | # Copy to conf.py and edit the required fields. |
---|
| | 2 | app_id = 'your facebook app id' |
---|
| | 3 | app_secret = 'your facebook app secret' |
---|
| | 4 | username = 'username to which the post has to be posted' |
---|
| | | | 7 | from postScraper.items import PostscraperItem | 7 | from postScraper.items import PostscraperItem |
---|
8 | | 8 | |
---|
9 | import facebook | 9 | import facebook |
---|
| | 10 | import conf |
---|
10 | | 11 | |
---|
11 | | 12 | |
---|
12 | class SwaraSpider(CrawlSpider): | 13 | class SwaraSpider(CrawlSpider): |
---|
… | | … | |
---|
22 | xpath = Selector() | 22 | xpath = Selector() |
---|
23 | loader = ItemLoader(item=PostscraperItem(), response=response) | 23 | loader = ItemLoader(item=PostscraperItem(), response=response) |
---|
24 | | 24 | |
---|
25 | loader.add_xpath('content', '//div[@class="report"]/p/text()') | | loader.add_xpath('content', '//div[@class="report"]/p/text()') |
---|
26 | loader.add_xpath('audio', | | loader.add_xpath('audio', |
---|
27 | '//div[@class="audiobox"]/object/@data', | | '//div[@class="audiobox"]/object/@data', |
---|
28 | re='(audio\/\d+\.mp3)') | | re='(audio\/\d+\.mp3)') |
---|
29 | loader.add_xpath('title', '//div[@class="report"]/h3/text()') | | loader.add_xpath('title', '//div[@class="report"]/h3/text()') |
---|
| | 25 | loader.add_xpath('content', '//div[@class="report"]/p/text()') | | | 26 | loader.add_xpath('audio', |
---|
| | 27 | '//div[@class="audiobox"]/object/@data', |
---|
| | 28 | re='(audio\/\d+\.mp3)') |
---|
| | 29 | loader.add_xpath('title', '//div[@class="report"]/h3/text()') |
---|
30 | | 30 | |
---|
31 | content = [{item: loader.get_collected_values(item)[0]} for item in | | content = [{item: loader.get_collected_values(item)[0]} for item in |
---|
32 | loader.load_item()] | | loader.load_item()] |
---|
33 | | | |
---|
34 | message = '{0}, {1}, http://cgnetswara.org/{2}'.format( | | message = '{0}, {1}, http://cgnetswara.org/{2}'.format( |
---|
35 | content[2]['title'].encode('utf8'), content[0]['content'].encode( | | content[2]['title'].encode('utf8'), content[0]['content'].encode( |
---|
36 | 'utf8'), | | 'utf8'), |
---|
37 | content[1]['audio'].encode('utf8')) | | content[1]['audio'].encode('utf8')) |
---|
38 | | | |
---|
39 | graph = facebook.GraphAPI('CAAInjfaxO5kBAIGSm6cp7HQKpFDZAcRYIaGDswF5ZAZCpQZBQB2U5kZCyRLH2ShLZBkyGbJPDt8QzzB64WbrcZCuAo3rH5P7b1a59vTUK3m0CCZAGZCtDjwcTp7VwOlZCeCRmdcX9x6bsjNBrNgpwgRIcgbAI4cSnK2pHYlhOZBO5x5f4ZAsc5YGklj8xuxjg2Bu3ZB8ZD') | | graph = facebook.GraphAPI('CAAInjfaxO5kBAIGSm6cp7HQKpFDZAcRYIaGDswF5ZAZCpQZBQB2U5kZCyRLH2ShLZBkyGbJPDt8QzzB64WbrcZCuAo3rH5P7b1a59vTUK3m0CCZAGZCtDjwcTp7VwOlZCeCRmdcX9x6bsjNBrNgpwgRIcgbAI4cSnK2pHYlhOZBO5x5f4ZAsc5YGklj8xuxjg2Bu3ZB8ZD') |
---|
40 | graph.put_object('me', 'feed', link=response.url, | | graph.put_object('me', 'feed', link=response.url, |
---|
41 | description=content[0]['content'].encode('utf8'), | | description=content[0]['content'].encode('utf8'), |
---|
42 | message="http://cgnetswara.org/"+content[1]['audio']) | | message="http://cgnetswara.org/"+content[1]['audio']) |
---|
| | 31 | content = [{item: loader.get_collected_values(item)[0]} for item in | | | 32 | loader.load_item()] |
---|
| | 33 | access_token = facebook.get_app_access_token(conf.app_id, |
---|
| | 34 | conf.app_secret) |
---|
| | 35 | graph = facebook.GraphAPI(access_token) |
---|
| | 36 | graph.put_object(conf.username, 'feed', link=response.url, |
---|
| | 37 | description=content[0]['content'].encode('utf8'), |
---|
| | 38 | message="http://cgnetswara.org/" + |
---|
| | 39 | content[1]['audio']) |
---|