Apr 29, 2017 11:07 AM
(This post was last modified: May 1, 2017 10:22 PM by Mrbadguy.)
I have started learning python and I have done my first mini project. It is a simple imgur downloader. You enter your search term and it will automatically create a folder and keep downloading all relevant images.
Also have a look at my clumsy code and i'm open for suggestions.
Code https://github.com/mrbadguy5/tinyimg
Apr 29, 2017 11:21 AM
(This post was last modified: Apr 29, 2017 11:24 AM by Riԁdle.)
(Apr 29, 2017 11:07 AM)Mrbadguy Wrote: I have started learning python and I have done my first mini project. It is a simple imgur downloader. You enter your search term and it will automatically create a folder and keep downloading all relevant images. It can be used for collecting pics to upload for your social media accounts :)
Also have a look at my clumsy code and i'm open for suggestions.
-snip-
I probably messed up somewhere..
PHP Code
<?php #! python3 import os, requests, bs4
# Change the directory os.chdir('C:\\Users\\MeanMachine\\Desktop\\workdir\\imgdownload') keyword = input('Enter your search tag: ') res = requests.get('https://imgur.com/search/score/all?q=%s' % keyword) imgur_bs_obj = bs4.BeautifulSoup(res.text, 'html.parser') images_element = imgur_bs_obj.select('#imagelist img') num = 1 linklist = [] os.mkdir(keyword) for i in images_element: a = str(images_element[i].get('src')) a = a[2:] a = a.replace('b.jpg', 'g.jpg').replace('i.i', 'http://i.i') linklist.append(a) for link in linklist: res = requests.get(linklist[link]) res.raise_for_status() with open(('%s\\' + os.path.basename(linklist[link])) % keyword, 'wb') as imageFile: print('Downloading File : %s' % num) for chunk in res.iter_content(): imageFile.write(chunk) num += 1
i like python lua js
I was expecting for you to share this program with us so we can download por.. i mean nature pictures for our IG yes 😉
Yeah, clicked to see the download link aswell to quotes, and I am serious unlike the post above.
okayyy
(Apr 29, 2017 11:28 AM)elfemage Wrote: Yeah, clicked to see the download link aswell to quotes, and I am serious unlike the post above.
I'm pretty sure it works, why don't you try it?
i like python lua js
Apr 29, 2017 11:31 AM
(This post was last modified: Apr 29, 2017 11:31 AM by Saint.)
(Apr 29, 2017 11:28 AM)elfemage Wrote: Yeah, clicked to see the download link aswell to quotes, and I am serious unlike the post above.
What you mean im serious aswell? Its a very usefull tool.
(Apr 29, 2017 11:28 AM)Mrbadguy Wrote: Lol ignore that part. I sent it to some of my friends who were manual downloading pics for social media. I just pasted the description.
Yea haha, you should release it on here tbh.
Apr 29, 2017 02:56 PM
(This post was last modified: Apr 29, 2017 03:07 PM by Ensky.)
Nice man!
A little pet peeve though:
Your code is really fucking ugly, following some aspects of the PEP8 style guide will help improve the look of your code.
https://www.python.org/dev/peps/pep-0008/
Cheers
My personal preference on styling your code
PHP Code
<?php #! python3 import os, requests, bs4
# Used to get the user's Operating System username. from getpass import getuser # Change the directory os.chdir('C:\\Users\\{}\\Desktop\\imgurThing'.format(getuser()))
keyword = input('Enter your search term: ') res = requests.get('https://imgur.com/search/score/all?q={}'.format(keyword)) imgur_bs_obj = bs4.BeautifulSoup(res.text, 'html.parser') images_element = imgur_bs_obj.select('#imagelist img')
num = 1 linklist = []
os.mkdir(keyword)
for i in range(len(images_element) -1): a = str(images_element[i].get('src'))[2:] a = a.replace('b.jpg','g.jpg').replace('i.i','http://i.i') linklist.append(a)
for i in range(len(linklist)): res = requests.get(linklist[i]) res.raise_for_status() imageFile = open('{}\\{}'.format(keyword, os.path.basename(linklist[i])), 'wb') print ('Downloading File: {}'.format(num))
for chunk in res.iter_content(): imageFile.write(chunk) imageFile.close() num += 1
You should always space your variables, parameters and shit like that.
kwargs (key word arguments) such as tkinter.Button(text='My Button') shouldn't have a space, however.
Cool I'll work on it. Thanks for feedback. :)
Nice Start Buddy
Can You Help Me Learning Python
Can You Provide Me Some Sources For Info ?
(Apr 30, 2017 02:17 AM)p1rat3sc0d3 Wrote: Nice Start Buddy
Can You Help Me Learning Python
Can You Provide Me Some Sources For Info ?
I started off with codecademy courses for python and now completed this book 'Automate the Boring Stuff with Python'. I'd say its the best book for starting off with python. Good Luck!🤝
|