-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #654 from praekeltfoundation/migrate-to-turn-scripts
Add bulk update turn contacts script
- Loading branch information
Showing
2 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
import sys | ||
from urllib.parse import urljoin | ||
|
||
import requests | ||
|
||
TURN_URL = "https://whatsapp-praekelt-cloud.turn.io" | ||
|
||
|
||
def bulk_update_turn_contacts(filename): | ||
data = open(filename, "rb") | ||
url = urljoin(TURN_URL, "v1/contacts") | ||
headers = { | ||
"Authorization": f"Bearer {os.environ['TURN_TOKEN']}", | ||
"content-type": "text/csv", | ||
} | ||
response = requests.post(url, data=data, headers=headers) | ||
|
||
print(response.status_code) | ||
|
||
f = open(f"result_{filename}", "wb") | ||
f.write(response.content) | ||
f.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
filename = sys.argv[1] | ||
bulk_update_turn_contacts(filename) |