Skip to content

Instantly share code, notes, and snippets.

@pandada8
Last active September 18, 2016 01:19
Show Gist options
  • Save pandada8/5e017ff91d0b98ba6b939113d9b6dcd6 to your computer and use it in GitHub Desktop.
Save pandada8/5e017ff91d0b98ba6b939113d9b6dcd6 to your computer and use it in GitHub Desktop.
import requests
import json
import time
import datetime
class MobCent():
def __init__(self):
self.args = {}
self.r = requests.session()
def _api(self, api, args):
arg = self.args.copy()
arg.update(args)
response = self.r.post(
"http://bbs.uestc.edu.cn/mobcent/app/web/index.php",
params={"r": api},
data=arg
)
try:
return response.json()
except:
return response.text
def login(self, username, password):
data = self._api("user/login", {
"password": password,
"username": username
})
self.args["accessToken"] = data["token"]
self.args["accessSecret"] = data["secret"]
print("Logined success")
def get_forum_list(self):
data = self._api("user/getsetting", {
"getSetting": {
"getSetting": json.dumps({"body": {"postInfo": {"forumIds": "0"}}})
}
})
return data["body"]["postInfo"]
def get_topic_list(self, forumid):
data = self._api("forum/topiclist", {
"filterType": "typeid",
"sortby": "new",
"pageSize": "20",
"boardId": forumid
})
return data["list"]
def notify(title, info):
ret = requests.post("https://api.pushbullet.com/v2/pushes", headers={"Content-Type": "application/json", "Access-Token": "<your token>"}, json={
"title": title,
"body": info,
"type": "note"
})
print("remained limit", ret.headers["X-Ratelimit-Remaining"])
print("Reseted at", datetime.datetime.fromtimestamp(int(ret.headers["X-Ratelimit-Reset"])))
def main():
mc = MobCent()
mc.login("<username>", "<password>")
last_update = (time.time() - 86400) * 1000
while True:
try:
for i in mc.get_topic_list(255):
l = int(i["last_reply_date"])
if l > last_update and i["title"].startswith("[出租-清水周边]"):
# update
notify(i["title"], i["user_nick_name"] + ":" + i["subject"] + "\n" + i["sourceWebUrl"] + "\n" + str(datetime.datetime.fromtimestamp(l / 1000)))
print(i["title"])
last_update = l
except Exception as e:
time.sleep(10)
print(e)
continue
time.sleep(1)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment