Renamed mirror to a module + added basic python3 http server

This commit is contained in:
Bofh 2021-02-07 01:21:58 +01:00
parent 02eff5188a
commit c799fb8e63
3 changed files with 42 additions and 5 deletions

Binary file not shown.

View File

@ -7,18 +7,18 @@ import json
import os
import re
def main():
data = getig_user_data('shakira')
print(json.dumps(data, indent=4))
def add_igaccount(acc_id):
data = getig_user_data(acc_id)
print(data)
# get all profile data from user:
# - display name
# - bio description
# - shared posts (images/videos)
# - much more info...
def getig_user_data(user_id):
def getig_user_data(acc_id):
return json.loads(
instagram_get('/{}/?__a=1'.format(user_id), 120000)
instagram_get('/{}/?__a=1'.format(acc_id), 120000)
)
# runs a basic GET request emulating Tor Browser

37
server.py Normal file
View File

@ -0,0 +1,37 @@
from http.server import BaseHTTPRequestHandler, HTTPServer
import igmirror
import re
hostName = "localhost"
serverPort = 8080
def update_igaccount(name):
print(name)
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
path = self.path.strip('/')
parts = path.split('/')
if len(parts) == 2:
# make sure account name contains only safe characters
accname = re.sub(r'[^a-zA-Z0-9_]+', '', parts[0])
if parts[1].lower() == 'add':
igmirror.add_igaccount(accname)
elif parts[1].lower() == 'update':
update_igaccount(accname)
self.wfile.write(bytes('OK', "utf-8"))
if __name__ == "__main__":
webServer = HTTPServer(('localhost', 8080), MyServer)
print("Server started http://%s:%s" % (hostName, serverPort))
try:
webServer.serve_forever()
except KeyboardInterrupt:
pass
webServer.server_close()
print("Server stopped.")