Add 'puremagic.py'

This commit is contained in:
Torma Kristóf 2020-06-20 21:28:31 +02:00
parent 6e7b3d1410
commit 41b31ac5dd
1 changed files with 41 additions and 0 deletions

41
puremagic.py Normal file
View File

@ -0,0 +1,41 @@
#!/usr/bin/env python3
from random import randrange, random
from time import sleep
import os.path
import json
from datetime import datetime
import requests
class PureMagic:
def __init__(self):
self.URL = "http://10.97.160.25/sample"
self.FILE = ['CommonStarling_100962.wav']
self.files = dict()
def choosefile(self):
index = randrange(10)
devid = randrange(15)
self.files = {
"file": (os.path.basename(self.FILE[index]), open(self.FILE[index], 'rb').read(), 'audio/wave',
{'Content-length': os.path.getsize(self.FILE[index])}),
"description": (
None, json.dumps({'date': datetime.now().isoformat(), 'device_id': str(devid)}), "application/json")
}
def send(self):
r = requests.post(self.URL, files=self.files)
print("Content: ", r.content)
print("Headers:", r.headers)
def work(self):
while True:
self.choosefile()
self.send()
sleep(random())
if __name__ == "__main__":
magic = PureMagic()
magic.work()