def _lj_mkpage_gen_opml(ljuser, password): fset = lj.get_fdata(ljuser) include_myself = bool(ljuser in fset['friends']) outlines = lj.get_opml(ljuser) ctx = {'credentials': encrypt({'ljuser': ljuser, 'password': password})} def mkfriend_ctx(f): return {'login': f, 'url': outlines['users'][f].htmlURL, 'journal_name': outlines['users'][f].text} mutual_friends = fset['friends'].intersection(fset['fans']) ctx['mutual_friends'] = [mkfriend_ctx(f) for f in mutual_friends] friends_of = fset['friends'].difference(fset['fans']) ctx['friends_of'] = [mkfriend_ctx(f) for f in friends_of] ctx['communities'] = [] for o in outlines['communities'].itervalues(): ctx['communities'].append({'url': o.htmlURL, 'login': o.login, 'journal_name': o.text}) return render_to_response('lj_mkopml.html', ctx)
def generic_mkfeed(req): if req.method == 'GET': return render_to_response('generic.html') elif req.method == 'POST': # FIXME: rewrite using django forms & proper validation param = {'feed': req.POST.get('feed'), 'user': req.POST.get('user'), 'password': req.POST.get('password')} feed = encrypt(param) return HttpResponseRedirect(req.build_absolute_uri('/feed/' + feed)) else: return HttpResponseNotAllowed(['GET', 'POST'])
def _lj_gen_opml(req): credentials = decrypt(req.POST['credentials']) friends = req.POST['friends'].split() communities = req.POST['communities'].split() ljuser = credentials['ljuser'] password = credentials['password'] outlines = lj.get_opml(ljuser) outlines['users'].update(outlines['communities']) outlines = outlines['users'] ctx = {'ljuser': ljuser} feeds = [] for who in friends + communities: o = outlines[who] if req.POST.get('read_' + who): param = {'feed': o.xmlURL + '?auth=digest', 'user': ljuser, 'password': password} if req.POST.get('cut_' + who): param['ljcut'] = 'body' xmlURL = req.build_absolute_uri('/feed/' + encrypt(param)) else: xmlURL = outlines[who].xmlURL if o.text.lower() != who.lower(): text = "%s (%s)" % (o.text, who) else: text = o.text feeds.append({'xmlURL': xmlURL, 'htmlURL': o.htmlURL, 'text': text}) ctx['feeds'] = feeds content = render_to_string('lj_opml.xml', ctx) resp = HttpResponse(content_type='text/xml', content=content) resp['Content-Disposition'] = 'attachment; filename="livejournal.opml"' return resp