Commit 703ef74d authored by Paco's avatar Paco
Browse files

Cosmetic change: run `black`

parent e5d28640
......@@ -4,30 +4,29 @@ import requests
import time
import datetime
message = ''
username = ''
oldTime = time.mktime(datetime.datetime.strptime("01/08/2018", "%d/%m/%Y").timetuple()) * 1000
baseUrl = 'https://team.picasoft.net/api/v4/'
message = ""
username = ""
oldTime = (
time.mktime(datetime.datetime.strptime("01/08/2018", "%d/%m/%Y").timetuple()) * 1000
)
baseUrl = "https://team.picasoft.net/api/v4/"
def get_auth():
return { 'Authorization': 'Bearer ' + token }
return {"Authorization": "Bearer " + token}
r = requests.post(
baseUrl + 'users/login',
json = {
'login_id': username,
'password': ''
})
r = requests.post(baseUrl + "users/login", json={"login_id": username, "password": ""})
token = r.headers['Token']
token = r.headers["Token"]
all_users = []
i = 0
while True:
users = requests.get(
baseUrl + 'users',
params = { 'per_page': '200', 'page': str(i) },
headers = get_auth()
baseUrl + "users",
params={"per_page": "200", "page": str(i)},
headers=get_auth(),
).json()
if users == []:
break
......@@ -37,31 +36,27 @@ while True:
me = requests.post(
baseUrl + 'users/usernames',
json = [ username ],
headers = get_auth()
baseUrl + "users/usernames", json=[username], headers=get_auth()
).json()[0]
for user in all_users:
sessions = requests.get(
baseUrl + 'users/' + user['id'] + '/sessions',
headers = get_auth()
baseUrl + "users/" + user["id"] + "/sessions", headers=get_auth()
).json()
for session in sessions:
if int(oldTime) < int(session['last_activity_at']):
if int(oldTime) < int(session["last_activity_at"]):
r = requests.post(
baseUrl + 'channels/direct',
json = [ user['id'], me['id'] ],
headers = get_auth()
baseUrl + "channels/direct",
json=[user["id"], me["id"]],
headers=get_auth(),
)
r = requests.post(
baseUrl + 'posts',
json = {
'channel_id': r.json()['id'],
'message': '### Salut ' + user['username'] + ' ! :D \n' + message,
baseUrl + "posts",
json={
"channel_id": r.json()["id"],
"message": "### Salut " + user["username"] + " ! :D \n" + message,
},
headers = get_auth()
headers=get_auth(),
)
print('Message sent to ' + user['username'])
print("Message sent to " + user["username"])
break
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment