Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 65 lines (52 sloc) 2.175 kb
2e8e893c » scorpion032
2009-04-28 Initial Import!
1 import urllib2,base64
2 from django.utils import simplejson
3 from django.shortcuts import render_to_response
4 import forms
5 #import wingdbstub
6 import settings
7
8 def is_follows(follower, following):
9
10 url = 'http://twitter.com/friendships/exists.json?user_a=%s&user_b=%s' %(
11 follower, following)
12
13 password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
14 top_level_url = "http://twitter.com/"
15 password_mgr.add_password(None, top_level_url, settings.TWNAME, settings.TWPASSWORD)
16 handler = urllib2.HTTPBasicAuthHandler(password_mgr)
17 opener = urllib2.build_opener(urllib2.HTTPHandler, handler)
18 urllib2.install_opener(opener)
19
20 try:
21 return simplejson.load(urllib2.urlopen(url))
22 except IOError, e:
23 #print "Something wrong. This shouldnt happen"
24 print e,"Protected user's details cant be found "
25 return False
26
27 def format_is_follows(follower, following):
28 fol = 'YES' if is_follows(follower,following) else 'NO'
29 new_entry = (fol,follower,following)
30 return "%s:%s:%s" %new_entry
31
32 def get_entry_tuples(str1="YES:str1:str2;NO:str3:str4"):
33 list1 = str1.split(';')
34 list2 = [tuple(i.split(":")) for i in list1]
35 return list2
36
37
38 def disp(req):
39 if req.method == 'POST':
40 form = forms.input_form(req.POST)
41
42 if form.is_valid():
43 new_str = format_is_follows(form.cleaned_data['follower'],
44 form.cleaned_data['following'])
45 old_str = req.POST['old']
46
47 form_data = "%s;%s" %(new_str,old_str)
48 entries = get_entry_tuples(form_data)[:-1]
49
50 payload = {'entries':entries,
51 'form':form,
52 'disp':True,
53 'form_data':form_data}
54 else:
55 payload = {'form':form,
56 'disp':True}
57 else:
58 form = forms.input_form()
59 payload = {'form':form,'disp':False}
60 return render_to_response('page3.html',payload,)
61
62
63 if __name__=='__main__':
64 #print is_follows('scobleizer','scorpion032')
65 print get_old_entries().insert(0,('a','b'))
Something went wrong with that request. Please try again.