forked from nukeador/20up
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPtuentI.py
More file actions
125 lines (102 loc) · 4.97 KB
/
APtuentI.py
File metadata and controls
125 lines (102 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#! /usr/bin/python
# -*- coding: utf-8 -*-
"""
Copyright (C) 2013 Borja Menendez Moreno
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Authors: Borja Menéndez Moreno <tuentiup@gmail.com>
Program for the backup of Tuenti, a Spanish social network.
This program downloads all of the photos, comments, private messages and
friends' information of a specific user.
"""
import urllib2, json
class APtuentI:
"""
The Tuenti API class, called APtuentI.
This class is used for the communication between the program and Tuenti,
allowing the program to do what it wants to backup a Tuenti account.
"""
def __init__(self):
self.sid = ''
self.apiversion = '0.7.1'
self.api = 'http://api.tuenti.com/api/'
def getResponse(self, data):
"""A method to retrieve a JSON response."""
request = urllib2.Request(self.api)
response = urllib2.urlopen(request, json.dumps(data))
response = json.load(response)
return response
def setSessionID(self, SID):
self.sid = SID
def doLogin(self):
"""Do the login in the Tuenti API server"""
data = {'version':self.apiversion, 'requests':[['getChallenge', \
{'type':'login'}]]}
return self.getResponse(data)
def getSession(self, timestamp, seed, passcode, appKey, email):
"""Get the session (the Session ID needed to do everything"""
data = {'version':self.apiversion, 'requests':[['getSession', \
{'timestamp':timestamp, 'seed':seed, 'passcode':passcode, \
'application_key':appKey, 'email':email}]]}
return self.getResponse(data)
def getUsersData(self, userid):
"""Get the user's data. It returns a JSON response with the
information."""
data = {'session_id':self.sid, 'version':self.apiversion, \
'requests':[['getUsersData', {'ids':[userid], \
'fields':['name', 'surname', 'phone_number', 'birthday']}]]}
return self.getResponse(data)
def getFriendsData(self):
"""Get the information about all the user's friends."""
data = {'session_id':self.sid, 'version':self.apiversion, \
'requests':[['getFriendsData',{'fields':['name', 'surname', \
'sex', 'phone_number', 'mvno_subscriber']}]]}
return self.getResponse(data)
def setUserStatus(self, status):
"""Set the user status."""
data = {'session_id':self.sid, 'version':self.apiversion, \
'requests':[['setUserStatus',{'body':status}]]}
return self.getResponse(data)
def getAlbumPhotos(self, album, page):
"""Get 20 photos of the album specified."""
data = {'session_id':self.sid, 'version':self.apiversion, \
'requests':[['getAlbumPhotos',{'album_id':album, \
'page':page, 'photos_per_page':20}]]}
return self.getResponse(data)
def getUserAlbums(self, page):
"""Get the user's albums."""
data = {'session_id':self.sid, 'version':self.apiversion, \
'requests':[['getUserAlbums',{'page':page, \
'albums_per_page':20}]]}
return self.getResponse(data)
def sendMessage(self, userid, message):
"""Send a private message to the specified user."""
data = {'session_id':self.sid, 'version':self.apiversion, \
'requests':[['sendMessage',{'body':message, \
'recipient':userid, 'legacy':'false'}]]}
return self.getResponse(data)
def getInbox(self, page):
"""Get the receive private messages."""
data = {'session_id':self.sid, 'version':self.apiversion, \
'requests':[['getInBox',{'page':page}]]}
return self.getResponse(data)
def getWall(self, page):
"""Get the wall with all the comments."""
data = {'session_id':self.sid, 'version':self.apiversion, \
'requests':[['getProfileWall',{'posts_per_page':20, \
'page':page}]]}
return self.getResponse(data)
def addPostToProfileWall(self, userid, message):
"""Add a post to the wall's specified user."""
data = {'session_id':self.sid, 'version':self.apiversion, \
'requests':[['addPostToProfileWall',{'user_id':userid, \
'body':message, 'legacy':'false'}]]}
return self.getResponse(data)