Jump to content

Need help with a Python script

BLLDoesTech

I have no clue what to do for this script

I need to create a module, that gives random images from URL's and prints them

 

This is for a discord bot if that info helps

Systems:

Main Gaming:                                                        Windows XP:

Ryzen 5 2600                                                               Intel Pentium 3

Asus RX 580 OC                                                     1GB DDR2

Patriot Viper DDR4 8GB                                         Asus Motherboard

Asus ROG B450-I                                                   Dell 300W

Corsair CX 450                                                       ATI Rage 128 Fury Pro

                                                                               

FreeNAS Server:                                                   Windows 98/95 duel boot:

I5 3400k                                                                  Pentium Pro

Patriot DDR3 8GB                                                  HP Vectra motherboard 

Gigabyte Ultra Durable                                           500MB RAM

Rosewill Glacier 600W                                           Soundblaster 16

                                                                               Matrox Mystique

Random PC:                                                         

AMD Phenom x4 850                                          Key:

Kukete A78                                                          Motherboard

Kingston 4GB DDR3                                            Memory

Dell 500W                                                            Power Supply

                                                                             Graphics Card

Other Gaming:                                                    Sound Card

Ryzen 5 2600                                                       Processor

Asus ROG Strix B350-F Gaming

MSI 1050 OC

Hyper-X 16GB DDR4

EVGA 750 B2

Link to comment
Share on other sites

Link to post
Share on other sites

I don't know Python, but I am just thinking the easiest way to achieve this is simply to make a list full of URL, roll a random number and then just print out the image with said URL.

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

You need to first choose a GUI framework.

You are not going to display an image with a command line interface are you?

 

Next you need to use the urllib  library to pull these images from the URL. 

 

Finally just use some random generator to randomly pick from the list. 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

6 hours ago, wasab said:

You need to first choose a GUI framework.

You are not going to display an image with a command line interface are you?

If they are making a discord bot, then discord is the interface.

 

@BLLDoesTech are you using a library like discord.py?

Gaming build:

CPU: i7-7700k (5.0ghz, 1.312v)

GPU(s): Asus Strix 1080ti OC (~2063mhz)

Memory: 32GB (4x8) DDR4 G.Skill TridentZ RGB 3000mhz

Motherboard: Asus Prime z270-AR

PSU: Seasonic Prime Titanium 850W

Cooler: Custom water loop (420mm rad + 360mm rad)

Case: Be quiet! Dark base pro 900 (silver)
Primary storage: Samsung 960 evo m.2 SSD (500gb)

Secondary storage: Samsung 850 evo SSD (250gb)

 

Server build:

OS: Ubuntu server 16.04 LTS (though will probably upgrade to 17.04 for better ryzen support)

CPU: Ryzen R7 1700x

Memory: Ballistix Sport LT 16GB

Motherboard: Asrock B350 m4 pro

PSU: Corsair CX550M

Cooler: Cooler master hyper 212 evo

Storage: 2TB WD Red x1, 128gb OCZ SSD for OS

Case: HAF 932 adv

 

Link to comment
Share on other sites

Link to post
Share on other sites

5 minutes ago, reniat said:

If they are making a discord bot, then discord is the interface.

 

@BLLDoesTech are you using a library like discord.py?

yes, I'm using discord.py

Systems:

Main Gaming:                                                        Windows XP:

Ryzen 5 2600                                                               Intel Pentium 3

Asus RX 580 OC                                                     1GB DDR2

Patriot Viper DDR4 8GB                                         Asus Motherboard

Asus ROG B450-I                                                   Dell 300W

Corsair CX 450                                                       ATI Rage 128 Fury Pro

                                                                               

FreeNAS Server:                                                   Windows 98/95 duel boot:

I5 3400k                                                                  Pentium Pro

Patriot DDR3 8GB                                                  HP Vectra motherboard 

Gigabyte Ultra Durable                                           500MB RAM

Rosewill Glacier 600W                                           Soundblaster 16

                                                                               Matrox Mystique

Random PC:                                                         

AMD Phenom x4 850                                          Key:

Kukete A78                                                          Motherboard

Kingston 4GB DDR3                                            Memory

Dell 500W                                                            Power Supply

                                                                             Graphics Card

Other Gaming:                                                    Sound Card

Ryzen 5 2600                                                       Processor

Asus ROG Strix B350-F Gaming

MSI 1050 OC

Hyper-X 16GB DDR4

EVGA 750 B2

Link to comment
Share on other sites

Link to post
Share on other sites

18 minutes ago, BLLDoesTech said:

yes, I'm using discord.py

I've never used discord.py, but it seems like the simplest way to do this is pick a command word (like "!random") and then in your on_message function for the bot, check to see if the message is that command and if so, do a message.channel.send(<random image url here>).

 

If you are not sure where on_message comes into it, there is a nice example here https://github.com/Rapptz/discord.py in the readme

 

as for getting the random numbers, if you are stuck on that, this is pretty much the most basic approach:

On 3/11/2019 at 1:18 PM, Minibois said:

I don't know Python, but I am just thinking the easiest way to achieve this is simply to make a list full of URL, roll a random number and then just print out the image with said URL.

 

Gaming build:

CPU: i7-7700k (5.0ghz, 1.312v)

GPU(s): Asus Strix 1080ti OC (~2063mhz)

Memory: 32GB (4x8) DDR4 G.Skill TridentZ RGB 3000mhz

Motherboard: Asus Prime z270-AR

PSU: Seasonic Prime Titanium 850W

Cooler: Custom water loop (420mm rad + 360mm rad)

Case: Be quiet! Dark base pro 900 (silver)
Primary storage: Samsung 960 evo m.2 SSD (500gb)

Secondary storage: Samsung 850 evo SSD (250gb)

 

Server build:

OS: Ubuntu server 16.04 LTS (though will probably upgrade to 17.04 for better ryzen support)

CPU: Ryzen R7 1700x

Memory: Ballistix Sport LT 16GB

Motherboard: Asrock B350 m4 pro

PSU: Corsair CX550M

Cooler: Cooler master hyper 212 evo

Storage: 2TB WD Red x1, 128gb OCZ SSD for OS

Case: HAF 932 adv

 

Link to comment
Share on other sites

Link to post
Share on other sites

7 hours ago, reniat said:

If they are making a discord bot, then discord is the interface.

 

@BLLDoesTech are you using a library like discord.py?

what is discord?

 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

8 hours ago, wasab said:

what is discord?

https://discordapp.com/
 

It's a popular chat interface. Think of it like the modern day equivalent of IRC communities. It's got a well made bot API https://discordapp.com/developers/docs/intro and a lot of solid community driven libraries (https://discord.js.org/#/, https://github.com/Rapptz/discord.py, etc.).

Gaming build:

CPU: i7-7700k (5.0ghz, 1.312v)

GPU(s): Asus Strix 1080ti OC (~2063mhz)

Memory: 32GB (4x8) DDR4 G.Skill TridentZ RGB 3000mhz

Motherboard: Asus Prime z270-AR

PSU: Seasonic Prime Titanium 850W

Cooler: Custom water loop (420mm rad + 360mm rad)

Case: Be quiet! Dark base pro 900 (silver)
Primary storage: Samsung 960 evo m.2 SSD (500gb)

Secondary storage: Samsung 850 evo SSD (250gb)

 

Server build:

OS: Ubuntu server 16.04 LTS (though will probably upgrade to 17.04 for better ryzen support)

CPU: Ryzen R7 1700x

Memory: Ballistix Sport LT 16GB

Motherboard: Asrock B350 m4 pro

PSU: Corsair CX550M

Cooler: Cooler master hyper 212 evo

Storage: 2TB WD Red x1, 128gb OCZ SSD for OS

Case: HAF 932 adv

 

Link to comment
Share on other sites

Link to post
Share on other sites

Before worrying about your Discord implementation, I would work on testing out web scraping in Python with images. A module like BeautifulSoup might be helpful, although there are others as well. Personally that would be the approach I would take. After figuring out how to get the images I want with Python successfully, then You could move on to your discord implementation.

Current PC build: [CPU: Intel i7 8700k] [GPU: GTX 1070 Asus ROG Strix] [Ram: Corsair LPX 32GB 3000MHz] [Mobo: Asus Prime Z370-A] [SSD: Samsung 970 EVO 500GB primary + Samsung 860 Evo 1TB secondary] [PSU: EVGA SuperNova G2 750w 80plus] [Monitors: Dual Dell Ultrasharp U2718Qs, 4k IPS] [Case: Fractal Design R5]

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×