Package: instabotnet
instagram-botnetWrite readable declarative yaml files to control your botnettemplate skema:TODOemit events for every actionemit events for new followers, new comments, comment references, usertag references in notifications at login timerewrite tests using pytestuse drone for ciemit event at login, adding info like followers nuber, posts number, following, timestamp (so i can later analyse using time window consisting of begin and end sessions)emit event at task endfix filter, filter should request a model data if given data is not sufficientimplement threads reading, at login timeimplement thread read messages, emit every message as eventdirect_v2_inbox() ->Response:viewer:Userinbox:threads:[thread_id:Strthread_v2_id:Strpending:Boolread_state:ReadStateusers:[User]items:[item_id:Intitem_type:"media_share"|"text"|"link"timestamp:Intuser_id:Intdevice_timestamp?:Intmedia_share?:Mediatext?:Strlink?:link_url:Str]thread_type:privatehas_newer:Boolhas_older:Boollast_seen_at:Anynewest_cursor:Stroldest_cursor:Stris_spam:Boollast_activity_at:Timestamplast_seen_at:[user_id]:timestamp:Timestampitem_id:Int]next_cursor:cursor_thread_v2_id:Intcursor_timestamp_seconds:Intunseen_count:Intunseen_count_ts:Intpending_requests_total:intstatus:"ok"|StrReadState:0 | 1direct_v2_thread(thread_id) # not thread_v2_id ->Response:thread:Threadto get last unseen messages:
1 call thread_v2_inbox()
2 if res['inbox']['unseen_count'] > 0
2 get the thread_ids where->addParam('persistentBadging', 'true')->addParam('use_unified_inbox', 'true');/*** Marks an item from given thread as seen.** @param string $threadId     Thread ID.* @param string $threadItemId Thread item ID.** @throws \InstagramAPI\Exception\InstagramException** @return \InstagramAPI\Response\DirectSeenItemResponse*/public function markItemSeen($threadId,$threadItemId){return $this->ig->request("direct_v2/threads/{$threadId}/items/{$threadItemId}/seen/")->addPost('use_unified_inbox', 'true')->addPost('action', 'mark_seen')->addPost('thread_id', $threadId)->addPost('item_id', $threadItemId)->addPost('_uuid', $this->ig->uuid)->addPost('_csrftoken', $this->ig->client->getToken())->setSignedPost(false)->getResponse(new Response\DirectSeenItemResponse());}Shell usageThe main module works on yaml script like these:name:test_commentbot:username:usernamepassword:passwordactions:-name:comment on 10 posts from @kimkardashiannodes:-kimkardashianedges:-user_feed:amount:10-comment:max:1comments:-["hello{author}!!!"]-["comestai?","comeva?"]-["urlworkstoo!http://instagram.com"]To execute the abovetest_comment.yamlrun:python3 -m instabotnet test_comment.yamlPython API usageTo use inside python modules:frominstabotnetimportexecuteexecute('test_comment.yaml',{'username':'user','some_variables':'bo'})Environment variables are accessible under the env objectThe variables passed to execute can be mutated, the execute function returns an object that contains the data collected from hescrapeaction.
The variables are mutated to support the multi script feature, where many templates are chained one after another in a single file and can pass data to the next template mutating the variables.
It is also useful to mutate the settings variable to update the cookies and other data for the next bot iteration.All the code inside {{ }} is evaluated by an eval call, this means that the templates can be filled with conditional and complex behaviors, for example making an http call to get the caption for uploading a photo, or get a random item from an array variable.
Inside eval code it is avaliablevariablesrandom moduleall the funcy functionsvariables inside the data objecturlopen module for making api callsjson module
A limitation of the code inside {{ }} is that it must consist only of one statement and can only return lists or strings.Every action inside a template will emit an event, all these events are avaliable in the object returned by execute:"template_name":"test_follow","action_name":"test_follow_famous_people","type":"follow","node":"kimkarkdashian","args":{},"metadata":{"username":"","proxy":""}Other events are emitted, for example when someone followes you:"type": "got_followed",
"node": "username"