def test_1(template): # mock.patch('instabotnet.api.API.do_login', new=lambda s: None).start() # with mock_method('instabotnet.api.instagram_private_api.client.Client', '_call_api', 'api.yaml', arg=1): print('running') print(template) result = execute(template, ({**os.environ, 'settings': {'cookies': {}}}), logger_format='%(message)s') print(json.dumps(result, indent=4))
def test_1(): with track_method('instabotnet.api.instagram_private_api.client.Client', '_call_api', 'api.yaml', arg=1): for name, template in all.items(): print(f'running {name}') print(template) result = execute(template, dotdict(os.environ)) print(json.dumps(result, indent=4))
def main(): print('inserisci l\'username instagram:') username = input() password = getpass.getpass('inserisci la password:\n') # password = input() print('inserisci il percorso del file:') path = input() try: result = execute(script, { 'username': username, 'password': password, 'path': path, }) events = [ event for event in result['events'] if event['type'] == 'upload_post' ] if not len(events): raise Exception('errore nel caricamento') url = events[0]['node']['url'] print(f'puoi trovare il post su "{url}"') except Exception as e: print(f'errore: probabilmente password sbagliata\n\n{e}')
def test_logging_handler(template): mock.patch('instabotnet.api.API.do_login', new=lambda s: None).start() with mock_method('instabotnet.api.instagram_private_api.client.Client', '_call_api', 'api.yaml', arg=1): print('running') print(template) class FileHandler(logging.Handler): terminator = '\n' def __init__(self, collection): logging.Handler.__init__(self) self.collection = collection def write_to_db(self, record): with open(self.collection, 'a') as f: f.write(record) def emit(self, record): try: msg = self.format(record) self.write_to_db(msg + '\n') except Exception: self.handleError(record) result = execute(template, ({**defaults, **os.environ}), handlers=[FileHandler('play_logs.txt')]) print(json.dumps(result, indent=4))
for path in tests: print() print() print() print() print() print() data = execute( load(path), { 'USERNAME': credentials.USER, 'username': credentials.USER, 'PASSWORD': credentials.PASS, 'password': credentials.PASS, # 'settings': open(credentials.USER + '_settings.json').read()) 'competitors': ['instagram'], 'inspirations': ['archillect.png'], 'captions': ['hey', 'bruh'], 'hashtags': ['pizza'], 'geotags': ['monaco'], 'comments': ['wow', 'awesome'], 'proxy': None, }) # print(yaml.dump(data, Dumper=Dumper, default_flow_style=False)) print('returned data:') print(json.dumps(dict(**data), indent=8)) time.sleep(3)
def main(): from instabotnet import execute execute(open('benchmarks/test.yml').read(), )
load_raw('src/routine.yml') print('starting routine') if not "settings_path" in data: settings_path = 'settings.json' data['settings_path'] = settings_path else: settings_path = data['settings_path'] if 'settings' in data: with open(settings_path, 'w') as f: f.write(json.dumps(data['settings'])) try: result = execute(script, data) print("result: ", json.dumps(result, indent=4)) with open(settings_path, 'r') as f: return_data['settings'] = json.load(f) # try: # url = result['reposted_images'][-1]['url'] # image = download(url) # return_data['uploadedMediasHashes'] += [make_hash(image)] # except Exception as e: # print('no media posted', e) except Exception as e: return_data = str(e) raise e from None
from instabotnet import execute import os import yaml import json path = os.environ['SCRIPT'] def load(path): with open(path) as f: return f.read() class Dumper(yaml.Dumper): def increase_indent(self, flow=False, indentless=False): return super(Dumper, self).increase_indent(flow, False) # print(yaml.dump(dict(**os.environ), Dumper=Dumper, default_flow_style=False)) data = execute(load(path), os.environ) print('returned data:') print(json.dumps(dict(**data), indent=4))