def feed(request): usergenres = request.user.genretouser.all() user = request.user if request.method == 'POST': form = PostingForm(request.POST) if form.is_valid(): if request.POST.get('facebookshare'): try: fb = FacebookProfiles.objects.get(user=user) fbk = Pyfb(settings.FACEBOOK_APP_ID, settings.FACEBOOK_SECRET_KEY) fbk.set_access_token(fb.fbk_token) fbk.publish(message=form.cleaned_data['content'], id=fb.fbk_id) except ObjectDoesNotExist: pass if request.POST.get('twittershare'): try: tw = TwitterProfiles.objects.get(user=user) twttr = tweepy.OAuthHandler(settings.TWITTER_CONSUMER_KEY, settings.TWITTER_CONSUMER_SECRET) twttr.set_access_token(tw.oauth_token, tw.oauth_secret) api = tweepy.API(twttr) me = api.me() api.update_status(form.cleaned_data['content'] + ' via @likewyss') except ObjectDoesNotExist: pass return HttpResponseRedirect('/feed/') else: form = PostingForm() var = RequestContext(request, { 'form':form, 'user':request.user, 'genres':usergenres }) return render_to_response('pages/feed.html', var)
query = """ PREFIX dcterms: <http://purl.org/dc/terms/> PREFIX niod: <http://purl.org/collections/nl/niod/> PREFIX skos: <http://www.w3.org/2004/02/skos/core#> PREFIX dbp-prop: <http://nl.dbpedia.org/property/> PREFIX dbp-res: <http://nl.dbpedia.org/resource/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?pref WHERE { ?entity niod:nerClass niod:nerclass-per; owl:sameAs <http://dbpedia.org/resource/Benito_Mussolini>; niod:pRef ?pref. } LIMIT 100 """ sparql.setQuery(query) sparql.setReturnFormat(JSON) results = sparql.query().convert() for result in results["results"]["bindings"]: xmldoc = urllib.urlopen(result["pref"]["value"]) msg = ''.join(xmldoc.readlines()[1:]) dom = minidom.parseString(msg) quotes = dom.getElementsByTagName('quote') for q in quotes: facebook.publish(getText(q.childNodes)) #print msg # facebook.publish(msg) print "Done."