r/learnpython • • Sep 27 '19

I made a bot that accuses random celebrities of being in 6ix9ine's 'Nine Trey Bloods' gang.

IDK why I did this, but here it is.

Every day, it accuses the most famous person on Famous Birthdays of being in 6ix9ine's 'Nine Trey Bloods'.

Here's how it works:

  • Uses bs4 to scrape Famous Birthdays for celebrity name & picture.

  • Uses Tweepy to search Twitter for the name, returns the most relevant user (if the celeb doesn't have a twitter, it still tags the first result which is kinda funny).

  • Uses Tweepy to attach media & tweet.

Full code.

p@

793 Upvotes

58 comments sorted by

6

u/jonaro00 Sep 27 '19

What did you use to execute the code once every day?

12

u/pattyperk Sep 28 '19

It runs via Cron on a Raspberry Pi Zero. I prefer this to the sleep method. If something goes wrong and you don't account for the error, your script will break. Running into an unexpected error with Cron is fine because it will run your entire script again later.

0

u/[deleted] Sep 28 '19

[deleted]

3

u/da_chosen1 Sep 28 '19

How does it work while the file isn't opened

3

u/bmw2621 Sep 28 '19

Cron is a process scheduler in linux. Or just runs a program at a configured interval. So he can set it to run the command python /path/to/69Snitches.py every day at noon.

Sleeping the program is a bad technique because the process would be running indefinitely, and if anything goes wrong, the whole thing stops. While with a scheduler. The script with just gets called again in 23.9 hours.

It's the same difference between calling your mom every day at noon and having an ongoing phone call where you never hang up, but just set the phone down and come back to it at noon the next day. Which is silly.

2

u/oramirite Sep 28 '19

Where do you run code like this?

1

u/pattyperk Sep 28 '19

I run it using cron on a Raspberry Pi Zero which just sits on my desk. Don't even have a monitor connected to it, just use ssh and vnc when necessary.

132

u/bl1ndside Sep 27 '19

I love the idea and execution. These silly projects make coding more fun and can make people excited about coding.

I made a twitter bot for my brother. He's a staunch Republican and I would grab Nancy Pelosi's tweets everyday and send them via text message to his phone.

20

u/maddruid Sep 27 '19

I need that code.

11

u/Dave5876 Sep 27 '19

Monetise this, lmao

3

u/Lostashoe Sep 27 '19

I need this code!!

2

u/DancingMidnightStar Sep 28 '19

Code? I have a friend...

2

u/eitauisunity Sep 28 '19

Replying in case the code is posted later.

2

u/IncredibleDork Sep 28 '19

Is this the line for the code?

-3

u/ready-ignite Sep 28 '19

That's wild. My brother is a staunch Democrat. After cat facts got old I started sending Nancy Pelosi's tweets by text message as a prank. Now he's a staunch Republican. He said he had no idea what politicians actually said, didn't follow the news much. Results may vary.

13

u/geoelectric Sep 28 '19

Seriously for a second, I think you’re an absolute hero.

You’ve demonstrated the brass ring incredibly clearly to a learning sub: these skills mean you can change the world from your keyboard with your brain. We now have something new (and pretty damned funny) that exists because you thought it’d be cool if it did and figured out how to translate that thought to code.

Taking this from what had to be one hell of a shower thought to an actual implementation and treating it seriously enough to have a repo, README, etc, is impressive work. Thanks so much for showing it to us.

21

u/Elite4alex Sep 27 '19

This is the kind of quality ridiculous content I come here to see

10

u/MonkeyNin Sep 27 '19

<eyes narrow>

That's exactly what a bot would say.

13

u/BruceJi 📦 Sep 28 '19
doLaugh(nervous)
say(‘No, no bots here’)

3

u/corpsie666 Sep 28 '19

That reminds me of the bots on ICQ

7

u/shoretel230 Sep 27 '19

Guido wanted it this way...

22

u/blabbities Redux FTW Sep 27 '19

Reading the title is hilarious. Reading how it works is funny. Good on you.

12

u/daermonn Sep 27 '19

This is the best post on this entire sub forever.

1

u/Alaska1429 Oct 02 '19

Just wondering, how did you put the posts on twitter? Is there a Twitter api or something?

1

u/pattyperk Oct 02 '19

There's a wrapper for the Twitter API called Tweepy that I use.

1

u/Alaska1429 Oct 02 '19

ok thankyou

6

u/[deleted] Sep 27 '19

You should check if Nine Trey Bloods needs a software engineer!

2

u/Roberto_Ayuni Sep 27 '19

This is just awesome

2

u/[deleted] Sep 28 '19

This is gold!

2

u/mastersuede Sep 28 '19

The streets is done lmao

2

u/spacemonkeykakarot Sep 28 '19

Beautiful, champ

2

u/cbat971 Sep 28 '19

I've been playing around with code to grab tweets by really cool Spanish accounts and texting them to me in an attempt to learn Spanish bit by bit every day.

2

u/Dr_Smeegee Sep 28 '19

I think I read a Charlie Stross novel about this script and some decerebrated kittens.

3

u/[deleted] Sep 27 '19

Oh my god. . . You mad man. I LOVE this!!! XD

2

u/YAYYYYYYYYY Sep 27 '19

I love this so much!

1

u/ameliaairh3art Oct 01 '19

This made my whole week

1

u/[deleted] Oct 18 '19

That's too fucking funny.

1

u/BioOrpheus Sep 27 '19

lol great job!

1

u/maddruid Sep 27 '19

Just saw today's tweet. Magnificent.

1

u/Hendawgydawg Sep 27 '19

Yo. This is great

-24

u/CuddleMeToSleep Sep 27 '19

That doesnt sound like a nice thing to do

0

u/[deleted] Sep 27 '19

[deleted]

91

u/Flkdnt Sep 27 '19

Elaborate pranks and code, the internet was made for this.

18

u/szirith Sep 27 '19

Mission accomplished!

18

u/thecodingrecruiter Sep 28 '19

Close your terminals and shut your laptops. It's finally finished.

11

u/eitauisunity Sep 28 '19

I recall there being a Yahoo commercial in the late 90's that referenced reaching the last page of the internet. Lol.

0

u/[deleted] Sep 28 '19

[deleted]

2

u/eitauisunity Sep 28 '19

I misremembered it being Yahoo. This was the commercial. So many nostalgic neurons fired. Thank you.

10

u/midnitte Sep 28 '19

Python enables memes. It's perfect.

8

u/mooburger resembles an abstract syntax tree Sep 27 '19

but cat pictures? what about those

0

u/[deleted] Sep 27 '19

[deleted]

10

u/Dave5876 Sep 27 '19

And soon, stitching.

0

u/[deleted] Sep 27 '19

[deleted]

13

u/[deleted] Sep 27 '19

It is useless stuff for fun calm down

5

u/ZypherXX Sep 27 '19

You must be fun at parties

1

u/[deleted] Oct 01 '19

[removed] — view removed comment

2

u/pattyperk Oct 01 '19
  1. So I'm not necessarily determining the most famous person myself. I'm actually just grabbing the first celebrity element on the page using Beautiful Soup. So, the first entry on the page is automatically the most famous person (according to them). You can see how I'm doing this in the get_celeb_name_and_image_from_famous_birthdays(url) function.

  2. I do download the images, and they're stored in a local folder and uploaded. This is necessary in order to upload the media to twitter.

  3. I've been thinking about making a video for my next bot, so watch out for that. I watched this video when first starting out, and it helped me understand how to use tweepy and the authentication process.

1

u/[deleted] Oct 01 '19

[removed] — view removed comment

1

u/pattyperk Oct 01 '19

Awesome! Let me know if you have any questions, more than happy to help.

0

u/[deleted] Sep 28 '19

[deleted]

4

u/bmw2621 Sep 28 '19

If someone looks at the twitter account and lacks the intelligence to notice every tweet is formatted the same, then they have bigger problems than "spreading misinformation" on the interwebs.

If a post is retweeted and third party lacks the intelligence to check account before propagating retweet, your concerns for them also should be more along the lines of "oh no, you lack the basic intelligence needed for human survival, please don't get hurt, should I help you cross the street?" And so on...

0

u/[deleted] Sep 28 '19

[deleted]

1

u/bmw2621 Sep 29 '19

So elderly have vested interest in 6ix9ine? Or care? En individual is responsible for what they believe and do not believe, and to research on there own.

Even our ”elderly" population has now grown up with TV and raised kids saying ”don't believe everything you see on tv".