Skip to content
This repository has been archived by the owner on Feb 12, 2018. It is now read-only.

Commit

Permalink
Added check to temp user data
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Karpitsky committed May 13, 2011
1 parent 8ac8fa6 commit 506e813
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 15 additions & 3 deletions clclt.py
Expand Up @@ -50,6 +50,7 @@ def UsersLookup(self, user_id):
uids.extend(user_id) uids.extend(user_id)
parameters['user_id'] = ','.join(["%s" % u for u in uids]) parameters['user_id'] = ','.join(["%s" % u for u in uids])
_json = self._FetchUrl(url, parameters=parameters) _json = self._FetchUrl(url, parameters=parameters)
print _json
data = json.loads(_json) data = json.loads(_json)
error = self._ParseError(data) error = self._ParseError(data)
if error is not None: if error is not None:
Expand All @@ -74,6 +75,8 @@ def PostDirectMessage(self, user, text):
url = 'https://api.twitter.com/1/direct_messages/new.json' url = 'https://api.twitter.com/1/direct_messages/new.json'
data = {'text': text, 'user': user} data = {'text': text, 'user': user}
_json = self._FetchUrl(url, post_data=data) _json = self._FetchUrl(url, post_data=data)
print data
print _json
return _json return _json


def PostUpdate(self, status): def PostUpdate(self, status):
Expand Down Expand Up @@ -147,11 +150,19 @@ def _UnGzip(self, response):
return url_data return url_data


class FilesHandler: class FilesHandler:
def get_json_from_file(self, file): def get_json_from_file(self, file, user_file=0):
try: try:
json_data = open(file) json_data = open(file)
try: try:
data = json.load(json_data) data = json.load(json_data)
if user_file == 1:
data['sub'] = data.get("sub", "follow")
data['dm'] = data.get("dm", "public")
for i in ["y", "f", "s"]:
if i in data:
pass
else:
data[i] = 0
except: except:
data = {} data = {}
data['sub'] = "follow" data['sub'] = "follow"
Expand All @@ -161,14 +172,15 @@ def get_json_from_file(self, file):
data['f'] = 0 data['f'] = 0
json_data.close() json_data.close()
except: except:
print "get_json_from_file error"
exit() exit()
return data return data


def get_user_info(self, user_id): def get_user_info(self, user_id):
user_file = ROOT_PATH + '/data/' + str(user_id) + ".json" user_file = ROOT_PATH + '/data/' + str(user_id) + ".json"
if not os.path.exists(user_file): if not os.path.exists(user_file):
open(user_file, 'w').close() open(user_file, 'w').close()
return self.get_json_from_file(user_file) return self.get_json_from_file(user_file, 1)


def save_info_to_file(self, user_id, user_data): def save_info_to_file(self, user_id, user_data):
user_file = ROOT_PATH + '/data/' + str(user_id) + ".json" user_file = ROOT_PATH + '/data/' + str(user_id) + ".json"
Expand Down Expand Up @@ -227,7 +239,7 @@ def do_calculate(self):
req_count = ceil(users_count/100.0) req_count = ceil(users_count/100.0)
i = 0 i = 0
while i < req_count: while i < req_count:
mod_req = self.requests % 350 mod_req = self.requests % 200
if mod_req == 0: if mod_req == 0:
self.bot += 1 self.bot += 1
self.th = TwitterHandler(self.bot) self.th = TwitterHandler(self.bot)
Expand Down
2 changes: 2 additions & 0 deletions data/.gitignore
@@ -0,0 +1,2 @@
*
!.gitignore

0 comments on commit 506e813

Please sign in to comment.