Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Twitch ban checker (Multi-threaded)

Made this while ago and decided to share because I don't really have need for this. Maybe this will help someone.
E: Updated multiple times. This post has most up-to-date version

(Jul 10, 2019 12:11 PM)Kallu609 Wrote:  Made this while ago and decided to share because I don't really have need for this. Maybe this will help someone.


so it just goes through a textfile and checks to see if the account is banned or not? what was your reasoning for first starting out the project
(Jul 10, 2019 12:19 PM)rabbi Wrote:  so it just goes through a textfile and checks to see if the account is banned or not? what was your reasoning for first starting out the project

I got request from fellow HF user to make program for him to mass check his accounts. I wouldn't call this a "project", a snippet at most.

I struggled a lot on beginning of my Python career with multithreading, hopefully this will help someone. It really isn't as hard as it first seems.
(Jul 10, 2019 12:22 PM)Kallu609 Wrote:  I got request from fellow HF user to make program for him to mass check his accounts. I wouldn't call this a "project", a snippet at most.

I struggled a lot on beginning of my Python career with multithreading, hopefully this will help someone. It really isn't as hard as it first seems.

ah i see, glad you could help someone out
Code
with lock:
    print(username.ljust(26, " ") + status)

    if not is_banned:
        open(not_banned_file, 'a').write(item + '\n')

Does this close the file handle correctly? I don't think so? Maybe I'm mistaken due to the 'with'.
(Jul 10, 2019 03:04 PM)l0lwtf Wrote:  
Code
with lock:
   print(username.ljust(26, " ") + status)

   if not is_banned:
       open(not_banned_file, 'a').write(item + '\n')

Does this close the file handle correctly? I don't think so? Maybe I'm mistaken due to the 'with'.

You're right. It doesn't close the file handle properly. I updated main post for better version.
Thanks for this Kallu, I'm pretty new to python but this looks pretty handy. I never really thought about multithreading, I'm going to go through your code and comment some of the lines to try and better understand it.
I like making Twitch related scripts too. You might want to add a 1 second delay between each request to avoid rate limit issues.
(Jul 12, 2019 04:50 AM)datguy.dev Wrote:  I like making Twitch related scripts too. You might want to add a 1 second delay between each request to avoid rate limit issues.

I don't know if there's any. I ran 100s of requests and it still gave the right response so I think you can abuse that API endpoint all you want.
(Jul 12, 2019 05:55 AM)Kallu609 Wrote:  I don't know if there's any. I ran 100s of requests and it still gave the right response so I think you can abuse that API endpoint all you want.

They have never really posted an official API rate limit tat I've seen. But there is code there as I've been hit with the "Rate Limit Exceeded" response. If you to become a problem, I'm sure they would ban your client id or IP. It's just a good practice to not beat on APIs if you don't have to.
r.text looks like a JSON response any reason you're not loading it into a dictionary?

¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´
(Jul 14, 2019 07:40 AM)vorticalbox Wrote:  r.text looks like a JSON response any reason you're not loading it into a dictionary?

It's more efficient to just read few characters from start of string than parsing JSON and checking it's value.
(Jul 14, 2019 12:51 PM)Kallu609 Wrote:  It's more efficient to just read few characters from start of string than parsing JSON and checking it's value.

doesn't it all ready have it as json? which you can access via .json()

¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´
(Jul 15, 2019 02:27 AM)vorticalbox Wrote:  doesn't it all ready have it as json? which you can access via .json()

Yes, it does have it as JSON but JSON parsing is slow.

Here's example running 1000000 iterations:
[Image: y0zUZY6.png]

Code that ran (Click to View)
(Jul 15, 2019 02:56 AM)Kallu609 Wrote:  Yes, it does have it as JSON but JSON parsing is slow.

Here's example running 1000000 iterations:
[Image: y0zUZY6.png]

Code that ran (Click to View)

fair enough I thought the request library already did the json.parse for you 👍

¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´


Possibly Related Threads...
Thread / Author Replies Views Last Post
by nucleo_type09Apr 23, 2024 04:10 PM 3 186 Apr 23, 2024 04:10 PM
Last Post: nucleo_type09
[Python] by skeyyy34Dec 17, 2021 06:55 PM 1 273 Dec 17, 2021 06:55 PM
Last Post: -Mr Mesmer
[Python] by DerpecDec 24, 2019 08:09 PM 9 282 Dec 24, 2019 08:09 PM
Last Post: Flash7475