Hack Forums
[Python] Faster* Instagram Username Checker (Filters Banned Accounts) - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] Faster* Instagram Username Checker (Filters Banned Accounts) (/showthread.php?tid=5582819)



Faster* Instagram Username Checker (Filters Banned Accounts) - Folks - Mar 23, 2017

After figuring out how to use asyncio and aiohttp I made an Instagram checker that is exponentially faster than the previous one I posted. If you are getting timed out change 'conns=50' to something lower.

Usage (Click to View)

Code (Click to View)


* - Goodies - Mar 24, 2017

Genuinely smiled at this.

I can't wait for people to get butthurt and flame ITT because they're not cool enough to learn asyncio.


* - Folks - Mar 24, 2017

(Mar 24, 2017 12:46 AM)Goodies Wrote:  Genuinely smiled at this.

I can't wait for people to get butthurt and flame ITT because they're not cool enough to learn asyncio.

Hey, it's harder than it looks 😊😝


* - Dotexe - Mar 24, 2017

Can you do this for c# ? :)


* - hunter24957 - Mar 24, 2017

There's actually a library called aiofiles which is used for asynchronous file I/O. Check it out! 🤝

Usage would be something like:
PHP Code

<?php 
import aiofiles

async def get_usernames
(inputfile):
    
async with aiofiles.open(inputfile, "r") as f:
        
usernames = await f.read()
        return 
usernames.split("\n") 



* - Folks - Mar 24, 2017

(Mar 24, 2017 07:44 AM)Dotexe1 Wrote:  Can you do this for c# ? :)

Any specific reason for this? If you are trying to learn it, I can always try it out but if you are looking for speed and functionality, this isn't going to change that much for such a small program.

Let me know and I can always take a crack at it when I am free!

(Mar 24, 2017 08:29 AM)hunter24957 Wrote:  There's actually a library called aiofiles which is used for asynchronous file I/O. Check it out! 🤝

Usage would be something like:
PHP Code

<?php 
import aiofiles

async def get_usernames
(inputfile):
    
async with aiofiles.open(inputfile, "r") as f:
        
usernames = await f.read()
        return 
usernames.split("\n") 

Although this is useful for some, what would this due for this? I am assuming it would read the file faster?

I'll have to check it out though ✌


* - hunter24957 - Mar 24, 2017

(Mar 24, 2017 08:38 AM)Folks Wrote:  Any specific reason for this? If you are trying to learn it, I can always try it out but if you are looking for speed and functionality, this isn't going to change that much for such a small program.

Let me know and I can always take a crack at it when I am free!


Although this is useful for some, what would this due for this? I am assuming it would read the file faster?

I'll have to check it out though ✌

It'll mainly help to make your program more asynchronous, it's great if you're writing to a file while making requests, which I'm assuming your program will do.


* - Dotexe - Mar 24, 2017

(Mar 24, 2017 08:38 AM)Folks Wrote:  Any specific reason for this? If you are trying to learn it, I can always try it out but if you are looking for speed and functionality, this isn't going to change that much for such a small program.

Let me know and I can always take a crack at it when I am free!
The reason is i want to learn how these things works ^_^ i'm not looking for speed and functionality, thanks in advance buddy 🤝


* - Folks - Mar 24, 2017

(Mar 24, 2017 08:42 AM)hunter24957 Wrote:  It'll mainly help to make your program more asynchronous, it's great if you're writing to a file while making requests, which I'm assuming your program will do.

Yea it does, after getting a response it writes to a file if the response contains the right data. Right now I have it just open the file as an appendable file because AFAIK opening a file multiple times isn't bad but writing can be.

(Mar 24, 2017 08:45 AM)Dotexe1 Wrote:  The reason is i want to learn how these things works ^_^ i'm not looking for speed and functionality, thanks in advance buddy 🤝

Yea sure, I don't know anything abuot C# but I've read it's similar to java which I know a bit about. I'll take a look into it over the weekend!


* - SIM-1866423 - Mar 24, 2017

"Python Enthusiast", waa welcome the py section fam !


* - Folks - Mar 24, 2017

(Mar 24, 2017 09:14 AM)Mnemosyne Wrote:  "Python Enthusiast", waa welcome the py section fam !

Yea, I decided to officialize my nerd status 🤗


* - youw0t - Mar 24, 2017

Very nice code man, I am trying to learn asyncio as well but one thing I don't understand in your code is why you have the loop set to None in the start_check function?

Keep up the good work

Code
async def start_check(igname, igpass, conns=50, loop=None):
    sem = asyncio.BoundedSemaphore(conns)
    async with aiohttp.ClientSession(loop=loop) as session:
        await login(igname, igpass, session)
        usernames = get_usernames(inputfile)
        tasks = [check_usernames(igname, igpass, username, sem, session, loop=loop) for username in usernames]
        await asyncio.gather(*tasks)



* - Goodies - Mar 24, 2017

(Mar 24, 2017 12:43 PM)youw0t Wrote:  Very nice code man, I am trying to learn asyncio as well but one thing I don't understand in your code is why you have the loop set to None in the start_check function?

Keep up the good work

Code
async def start_check(igname, igpass, conns=50, loop=None):
    sem = asyncio.BoundedSemaphore(conns)
    async with aiohttp.ClientSession(loop=loop) as session:
        await login(igname, igpass, session)
        usernames = get_usernames(inputfile)
        tasks = [check_usernames(igname, igpass, username, sem, session, loop=loop) for username in usernames]
        await asyncio.gather(*tasks)

What I do is something like this:
PHP Code

<?php 
async def coro
(a, b, *, loop=None):
    
loop = loop or asyncio.get_event_loop() 

This (or similar) is at the beginning of most asyncio functions. If no loop is explicitly provided, it will get the one defined in the current thread (each thread can have one loop defined and, by default, only the main thread has an event loop defined.


* - youw0t - Mar 24, 2017

(Mar 24, 2017 12:49 PM)Goodies Wrote:  What I do is something like this:
PHP Code

<?php 
async def coro
(a, b, *, loop=None):
    
loop = loop or asyncio.get_event_loop() 

This (or similar) is at the beginning of most asyncio functions. If no loop is explicitly provided, it will get the one defined in the current thread (each thread can have one loop defined and, by default, only the main thread has an event loop defined.

Ah, that cleared things up. Thanks for the explanation


* - P3T3R - Mar 28, 2017

Does this also work to see if an email is in use or is not in use? Thanks in advance.