Add 'puremagic.py'
This commit is contained in:
		
							
								
								
									
										41
									
								
								puremagic.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								puremagic.py
									
									
									
									
									
										Normal 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()
 | 
			
		||||
		Reference in New Issue
	
	Block a user