-3

I'm trying to create a script that will auto-downloads the Bing wallpaper of the day so it can be my desktop background, and so far I found out that the url for it is hidden in the g_img tag. So what I've done so far is find the position of g_img={url: " and then for the next ".

 from os.path import expanduser
 import urllib
 import os
 HOME = expanduser("~")
 os.system("wget https://www.bing.com")

 str="g_img={url: \""
 file="index.html"

 pos=open(file, 'r').read().find(str)
 pos2=open(file, 'r').read().find("\"", pos)

 # function to get the url string
 # function to get PicName

 BingBackUrl= "https://www.bing.com%s" % url
 urllib.urlretrieve(BingBackUrl, PicName)
 os.system("gsettings set org.gnome.desktop.background picture-uri file://%s/%s" % (HOME, PicName))
Bored
  • 21
  • 1
  • 5

1 Answers1

1

something like this: I'd use with so the file gets closed at the end, so:

with open(file) as data:
    urlraw = data.read()
    pos = urlraw.find(str) + len(str)
    pos2 = urlraw.find("\"")
PicName = urlraw[pos:pos2]

The file is just a string so there's no XY it's all 1 dimension. Then you need to take into account you want the end of the first string not the beginning, hence adding len(str).

Should basically do what you need, if I've read your requirements properly.

Keef Baker
  • 641
  • 4
  • 22