Help for python download path

Requests, suggestions, support, and everything else python / plugin related.
Post Reply
senna99
Posts: 5
Joined: Fri Mar 28, 2014 9:38 am

Help for python download path

Post by senna99 »

I use this version of python ,where I need to type C:\New folder for download path?
I need this for my skin,to always have fresh photos from web.

Best Regards


# imageDownloader.py
# Finds and downloads all images from any given URL.
# FB - 201009083
import urllib2
from os.path import basename
from urlparse import urlsplit
from BeautifulSoup import BeautifulSoup # for HTML parsing

url = "http://www.yahoo.com"
urlContent = urllib2.urlopen(url).read()
soup = BeautifulSoup(''.join(urlContent))
imgTags = soup.findAll('img') # find all image tags

# download all images
for imgTag in imgTags:
imgUrl = imgTag['src']
try:

imgData = urllib2.urlopen(imgUrl).read()
fileName = basename(urlsplit(imgUrl)[2])
output = open(fileName,'wb')
output.write(imgData)
output.close()
except:
pass
User avatar
Dom DXecutioner
Posts: 585
Joined: Thu Jul 05, 2012 11:59 pm
Location: California
Has thanked: 249 times
Been thanked: 219 times
Contact:

Help for python download path

Post by Dom DXecutioner »

Quick response as it's hard to post code from a phone... :)

Code: Select all

# set script id, which is the name of the script
SCRIPT_ID = "ImageDownloader"
# set the base directory for saving, which is the script data folder for the current user
BASE_FOLDER = xbmc.translatePath(special://profile/script_data/"


# your code...
...
# create folder path
FilePath = os.path.join(BASE_FOLDER, SCRIPT_ID)

# test directories exist, otherwise make them
If not os.path.exists(FilePath):
     os.makedirs(FilePath)

# put the path together
FileNameAndPath = os.path.join(FilePath, fileName)

# the rest of your code
...
Untested of course, but that's the basic idea...
Image
senna99
Posts: 5
Joined: Fri Mar 28, 2014 9:38 am

Re: Help for python download path

Post by senna99 »

Thank you for your reply Dom

Unfortunately I have no knowledge as you,I've been trying to use your codes from xbox.gamertag.py but without success.
If you can help me please write me how to be looked to the whole structure .py with your and my codes together.
Thank you in advance

Best Regards
User avatar
Dom DXecutioner
Posts: 585
Joined: Thu Jul 05, 2012 11:59 pm
Location: California
Has thanked: 249 times
Been thanked: 219 times
Contact:

Help for python download path

Post by Dom DXecutioner »

That's out of the scope of your original post
Image
senna99
Posts: 5
Joined: Fri Mar 28, 2014 9:38 am

Re: Help for python download path

Post by senna99 »

Hello Dom

I got the message,I will try to write the rest of the codes.
But thank you for the first posts,I will try to use these codes.

Best Regards
Post Reply