क्या कोई ऐसा तरीका है जिससे मैं बिंग पृष्ठभूमि छवि को प्रोग्रामेटिक रूप से प्राप्त कर सकता हूं?
बिंग एपीआई इस तरह की कार्यक्षमता प्रदान करने के लिए प्रतीत नहीं होता है, शायद वहाँ एक और तरीका है?
क्या कोई ऐसा तरीका है जिससे मैं बिंग पृष्ठभूमि छवि को प्रोग्रामेटिक रूप से प्राप्त कर सकता हूं?
बिंग एपीआई इस तरह की कार्यक्षमता प्रदान करने के लिए प्रतीत नहीं होता है, शायद वहाँ एक और तरीका है?
जवाबों:
मुझे लगता है कि सबसे अच्छा तरीका यह है कि वे अपने AJAX कॉल के माध्यम से खुद को ऐसा करने के तरीके की नकल कर रहे हैं।
वे इस URL को कॉल करते हैं और XML डिसेरिएलाइज़ेशन के माध्यम से जानकारी निकालते हैं।
XML: http://www.bing.com/HPImageArchive.aspx?format=xml&idx=0&n=1&mkt=en-US
JSON: http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US
RSS: http://www.bing.com/HPImageArchive.aspx?format=rss&idx=0&n=1&mkt=en-US
mkt
विशेषता जाहिर'en-US' तुलना में एक अलग क्षेत्र के लिए बदला जा सकता है, लेकिन यह भी पूरी तरह से अगर आप एक विशिष्ट क्षेत्र के बारे में परवाह नहीं है बाहर कर दिया जाए जा सकता है।
ध्यान दें कि _1366x768.jpg
छवि के नामों में जो प्रत्यय जोड़ा गया है, वह विभिन्न प्रस्तावों (जैसे _1920x1080.jpg
पूर्ण HD और संभवतः अन्य) के लिए परिवर्तनीय प्रतीत होता है ।
यहाँ XML प्रारूप में 9/28/2013 के रूप में डेटा का एक डंप है।
<?xml version="1.0" encoding="utf-8"?>
<images>
<image>
<startdate>20130928</startdate>
<fullstartdate>201309280000</fullstartdate>
<enddate>20130929</enddate>
<url>/az/hprichbg/rb/LakeTurkana_EN-US15976511099_1366x768.jpg</url>
<urlBase>/az/hprichbg/rb/LakeTurkana_EN-US15976511099</urlBase>
<copyright>Lava rock pools at the southern end of Lake Turkana, in Kenya (© Nigel Pavitt/Corbis)</copyright>
<copyrightlink>http://www.bing.com/search?q=Lake+Turkana%2C+Kenya&form=hpcapt</copyrightlink>
<drk>1</drk>
<top>1</top>
<bot>1</bot>
<hotspots>
<hotspot>
<desc>These are the southern reaches of a lake...</desc>
<link>http://www.bing.com/maps/?v=2&cp=2.794725~37.335197&lvl=7&dir=0&sty=b&q=Lake%20Turkana%2C%20Kenya&form=hphot1</link>
<query>That stretches for 180 miles, up into another country</query>
<LocX>15</LocX>
<LocY>33</LocY>
</hotspot>
<hotspot>
<desc>This body of water was once called the Jade Sea.</desc>
<link>http://www.bing.com/search?q=green+algae&form=hphot2</link>
<query>What gives the water here its sometimes vibrant hue?</query>
<LocX>37</LocX>
<LocY>42</LocY>
</hotspot>
<hotspot>
<desc>One of the world's most powerful predators lives here.</desc>
<link>http://www.bing.com/videos/search?q=Underwater+Croc+Cams+National+Geographic&FORM=hphot3#view=detail&mid=D25E1909D3514A8732C5D25E1909D3514A8732C5</link>
<query>See some rare underwater footage of the beast</query>
<LocX>66</LocX>
<LocY>33</LocY>
</hotspot>
<hotspot>
<desc>Many fossils of ancient human ancestors have been uncovered in the surrounding area.</desc>
<link>http://www.bing.com/search?q=Turkana+Boy&form=hphot4</link>
<query>One skeleton was so complete, paleoanthropologists gave him a name</query>
<LocX>82</LocX>
<LocY>41</LocY>
</hotspot>
</hotspots>
<messages></messages>
</image>
<tooltips>
<loadMessage>
<message>Indlæser...</message>
</loadMessage>
<previousImage>
<text>Forrige</text>
</previousImage>
<nextImage>
<text>Næste</text>
</nextImage>
<play>
<text>Afspil</text>
</play>
<pause>
<text>Pause</text>
</pause>
</tooltips>
</images>
_1920x1200
काम करने के लिए कुछ भी, यानी भी 1920x1080
और अन्य।
&mkt=en-US
भाग नहीं है । यह तब भी है जब मेरे पास "अंग्रेज़ी-संयुक्त राज्य" के लिए सेट किया गया ऐप है।
jsonp
, लेकिन ऐसा नहीं लगता है जैसे वे अनुमति देते हैं।
मुझे दिन के बिंग इमेज के JSON प्रारूप को लाने का एक तरीका मिला
n=
आपके द्वारा चाहा गया चित्र नहीं है (आप इंटेगर का उपयोग कर सकते हैं ),
mkt=
आपका स्थान (उदाहरण: en-US )
{
"images": [
{
"startdate": "20141214",
"fullstartdate": "201412141830",
"enddate": "20141215",
"url": "\/az\/hprichbg\/rb\/BlackButte_EN-IN7038391888_1920x1080.jpg",
"urlbase": "\/az\/hprichbg\/rb\/BlackButte_EN-IN7038391888",
"copyright": "Black Butte, seen from the Mount Jefferson Wilderness, Oregon, USA (\u00a9 Marc Adamus\/Aurora Photos)",
"copyrightlink": "http:\/\/www.bing.com\/search?q=Black+Butte&qs=n&form=hpcapt&mkt=en-in&pq=black+butte&sc=8-11&sp=-1&sk=&cvid=228ac7f125f94bbaafd4a4abd4f9a32d",
"wp": true,
"hsh": "94156ae1e2e1be49f9b739d2b7bff65c",
"drk": 1,
"top": 1,
"bot": 1,
"hs": [
],
"msg": [
{
"title": "How does it feel\u2026",
"link": "http:\/\/www.bing.com\/videos\/search?q=Climbing+Black+Butte&FORM=pgbar1&mkt=en-in#view=detail&mid=58BDB2F2B9FCB85D597558BDB2F2B9FCB85D5975",
"text": "To climb 1961.7 m?"
},
{
"title": "On top of the world",
"link": "http:\/\/www.bing.com\/images\/search?q=Pictures+From+the+Top+of+Mount+Everest&FORM=pgbar2&mkt=en-in",
"text": "It's mountaineer's dream view"
}
]
}
],
"tooltips": {
"loading": "Loading...",
"previous": "Previous",
"next": "Next",
"walle": "This image is not available to download as wallpaper.",
"walls": "Download this image. Use of this image is restricted to wallpaper only."
}
}
से उपयोग url
करेंimages[]
और इसे जोड़ें 'http://bing.com'
यहाँ url है "url": "\/az\/hprichbg\/rb\/DayGecko_EN-US8730336235_1366x768.jpg"
Unexpected token :
हैhttps://www.bing.com/HPImageArchive.aspx?format=js&idx=8&n=8&mkt=en-US&callback=jQuery111100034959779751375653_1518009655771&_=1518009655772
Microsoft ने हाल ही में विंडोज 7 के लिए बिंग डायनामिक थीम प्रकाशित किया है , जिसमें बिंग वॉलपेपर के लिंक के साथ आरएसएस फीड है ।
एक पायथन स्क्रिप्ट भी है जो बिंग वेबसाइट को लोड करने और सही छवि URL का अनुमान लगाने की कोशिश करती है, लेकिन मेरे अनुभव से, यह आमतौर पर आरएसएस फ़ीड की पेशकश की तुलना में कम रिज़ॉल्यूशन की छवि में होता है।
मुझे पार्टी में देरी हो रही है, लेकिन अगर किसी को PHP कार्यान्वयन की आवश्यकता है: मैंने एक साधारण वर्ग लिखा है जो प्रक्रिया को संभालता है:
एक लाइनर PowerShell (3.0 या अधिक)
irm
के लिए एक उपनाम है Invoke-RestMethod
irm "bing.com$((irm "bing.com/HPImageArchive.aspx?format=js&mkt=en-IN&n=1").images[0].url)" -OutFile bing.jpg
मुझे बिंग छवियां भी पसंद हैं लेकिन छवियों को डाउनलोड करने के उद्देश्य से उनका ऐप बहुत अधिक फूला हुआ है। फ़िडलर के साथ संबंध का विश्लेषण करने के बाद, मैंने यह कोड लिखा। 1920x1200 बिंग लोगो एम्बेडेड के साथ आता है, लेकिन कम संकल्प में यह नहीं है।
आपके द्वारा सेट की गई छवि फ़ोल्डर से विंडो आपको यादृच्छिक छवियां दिखा सकती है, इसलिए जैसे ही आप उन्हें दैनिक रूप से डाउनलोड करते हैं, यह आपको अधिक यादृच्छिक छवियां दिखाएगा। यदि आप "इमेजडायर" रखते हैं, तो आपको उस फ़ोल्डर पर अनुमतियों को बदलने की आवश्यकता है या यह दुर्घटनाग्रस्त हो जाएगा, मैंने कैच की त्रुटियों से परेशान नहीं किया। अंत में, यदि आप अपने वॉलपेपर को आज की छवि पर सेट करना चाहते हैं तो लाइनों को अन-कमेंट करें या आप प्रोग्राम को चलाने के लिए एक कार्य बना सकते हैं, लॉगऑन के एक मिनट बाद।
using System;
using System.IO;
using System.Net;
//using System.Runtime.InteropServices;
namespace Bing
{
class Program
{
// [DllImport("user32.dll", CharSet = CharSet.Auto)]
// private static extern Int32 SystemParametersInfo(UInt32 uiAction, UInt32 uiParam, String pvParam, UInt32 fWinIni);
private static String imgDir = @"C:\Windows\Web\Wallpaper\Bing\";
static void Main(string[] args)
{
String imageFileName;
if (!Directory.Exists(imgDir))
Directory.CreateDirectory(imgDir);
for (byte i = 6; i >= 0; i--)
{
imageFileName = imgDir + DateTime.Today.AddDays(-i).ToString("yyy-MM-dd") + ".jpg";
if (!File.Exists(imageFileName))
{
string response = null;
Connect(ref response, i);
ProcessXml(ref response);
using (WebClient client = new WebClient())
client.DownloadFile("http://www.bing.com" + response + "_1920x1200.jpg", imageFileName);
}
}
//SystemParametersInfo(20, 0, imageFileName, 0x01 | 0x02);
}
private static void Connect(ref string res, byte i)
{
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create("http://www.bing.com/hpimagearchive.aspx?format=xml&idx=" + i + "&n=1&mbl=1&mkt=en-ww");
webrequest.KeepAlive = false;
webrequest.Method = "GET";
using (HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse())
using (StreamReader loResponseStream = new StreamReader(webresponse.GetResponseStream()))
res = loResponseStream.ReadToEnd();
}
private static void ProcessXml(ref string xmlString)
{
using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(new StringReader(xmlString)))
{
reader.ReadToFollowing("urlBase");
xmlString = reader.ReadElementContentAsString();
}
}
}
}
मैंने देखा कि बहुत से लोग नए आरएसएस लिंक के लिए भी पूछ रहे हैं, बस URL में प्रारूप पैरामीटर को "rss" में बदलें।
RSS : http://www.bing.com/HPImageArchive.aspx?format=rss&idx=0&n=1&mkt=en-US
यह जावास्क्रिप्ट एक div की पृष्ठभूमि की छवि को वर्तमान दिन की पृष्ठभूमि की छवि में बदलकर 'api के साथ क्या करना है' का उत्तर देगा।
function PullBackground() {
var ajaxRequest = new XMLHttpRequest(), background = '';
ajaxRequest.open('POST', "http://www.bing.com/HPImageArchive.aspx?format=xml&idx=0&n=1&mkt=en-US", true);
ajaxRequest.setRequestHeader("Connection", "close");
ajaxRequest.send('');
ajaxRequest.onreadystatechange = function () {
if (ajaxRequest.readyState == 4) {
background = ajaxRequest.responseText;
var res = background.split("<url>");
var res1 = res[1].split("</url>");
background = res1[0];
document.getElementById('NameOfTheDivToChange').style.backgroundImage = "url('http://bing.com" + background + "')"
document.getElementById('NameOfTheDivToChange').style.backgroundSize = "100%";
}
}
}
यदि किसी को संभावित कार्यान्वयन की तलाश है, तो मैंने अपनी पृष्ठभूमि को बिंग इमेज ऑफ़ द डे के रूप में डाउनलोड करने, सहेजने और सेट करने के लिए C # में एक छोटा कमांड-लाइन प्रोग्राम लिखा। अपनी व्यक्तिगत जरूरतों के लिए इसे संशोधित करने के लिए स्वतंत्र महसूस करें। https://github.com/josueespinosa/BingBackground
using Microsoft.Win32;
using Newtonsoft.Json;
using System;
using System.Drawing;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace BingBackground
{
class BingBackground
{
private static void Main(string[] args)
{
string urlBase = GetBackgroundUrlBase();
Image background = DownloadBackground(urlBase + GetResolutionExtension(urlBase));
SaveBackground(background);
SetBackground(background, PicturePosition.Fill);
}
private static dynamic DownloadJson()
{
using (WebClient webClient = new WebClient())
{
Console.WriteLine("Downloading JSON...");
string jsonString = webClient.DownloadString("https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US");
return JsonConvert.DeserializeObject<dynamic>(jsonString);
}
}
private static string GetBackgroundUrlBase()
{
dynamic jsonObject = DownloadJson();
return "https://www.bing.com" + jsonObject.images[0].urlbase;
}
private static string GetBackgroundTitle()
{
dynamic jsonObject = DownloadJson();
string copyrightText = jsonObject.images[0].copyright;
return copyrightText.Substring(0, copyrightText.IndexOf(" ("));
}
private static bool WebsiteExists(string url)
{
try
{
WebRequest request = WebRequest.Create(url);
request.Method = "HEAD";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
return response.StatusCode == HttpStatusCode.OK;
}
catch
{
return false;
}
}
private static string GetResolutionExtension(string url)
{
Rectangle resolution = Screen.PrimaryScreen.Bounds;
string widthByHeight = resolution.Width + "x" + resolution.Height;
string potentialExtension = "_" + widthByHeight + ".jpg";
if (WebsiteExists(url + potentialExtension))
{
Console.WriteLine("Background for " + widthByHeight + " found.");
return potentialExtension;
}
else
{
Console.WriteLine("No background for " + widthByHeight + " was found.");
Console.WriteLine("Using 1920x1080 instead.");
return "_1920x1080.jpg";
}
}
private static Image DownloadBackground(string url)
{
Console.WriteLine("Downloading background...");
WebRequest request = WebRequest.Create(url);
WebResponse reponse = request.GetResponse();
Stream stream = reponse.GetResponseStream();
return Image.FromStream(stream);
}
private static string GetBackgroundImagePath()
{
string directory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "Bing Backgrounds", DateTime.Now.Year.ToString());
Directory.CreateDirectory(directory);
return Path.Combine(directory, DateTime.Now.ToString("M-d-yyyy") + ".bmp");
}
private static void SaveBackground(Image background)
{
Console.WriteLine("Saving background...");
background.Save(GetBackgroundImagePath(), System.Drawing.Imaging.ImageFormat.Bmp);
}
private enum PicturePosition
{
Tile,
Center,
Stretch,
Fit,
Fill
}
internal sealed class NativeMethods
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
}
private static void SetBackground(Image background, PicturePosition style)
{
Console.WriteLine("Setting background...");
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(Path.Combine("Control Panel", "Desktop"), true))
{
switch (style)
{
case PicturePosition.Tile:
key.SetValue("PicturePosition", "0");
key.SetValue("TileWallpaper", "1");
break;
case PicturePosition.Center:
key.SetValue("PicturePosition", "0");
key.SetValue("TileWallpaper", "0");
break;
case PicturePosition.Stretch:
key.SetValue("PicturePosition", "2");
key.SetValue("TileWallpaper", "0");
break;
case PicturePosition.Fit:
key.SetValue("PicturePosition", "6");
key.SetValue("TileWallpaper", "0");
break;
case PicturePosition.Fill:
key.SetValue("PicturePosition", "10");
key.SetValue("TileWallpaper", "0");
break;
}
}
const int SetDesktopBackground = 20;
const int UpdateIniFile = 1;
const int SendWindowsIniChange = 2;
NativeMethods.SystemParametersInfo(SetDesktopBackground, 0, GetBackgroundImagePath(), UpdateIniFile | SendWindowsIniChange);
}
}
}
सरल पॉवरशेल, एक फ़ोल्डर में रखें, विंडोज टास्क शेड्यूलर में एक दैनिक कार्य बनाएं, स्क्रिप्ट अपने रन फ़ोल्डर में छवियों को बचाता है, फिर अपने डेस्कटॉप पृष्ठभूमि सेटिंग्स में उस फ़ोल्डर को पृष्ठभूमि के रूप में चुनें।
[xml]$doc = (New-Object System.Net.WebClient).DownloadString("https://www.bing.com/HPImageArchive.aspx?format=xml&idx=0&n=1&mkt=ru-RU")
$url = $doc.images.image.url
$url = "https://www.bing.com/" + $url -replace "_1366x768","_1920x1200"
Write-Output $url
$fileName = Split-Path $url -leaf
$output = "$PSScriptRoot\$fileName"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Saved to: $output Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"
यहाँ एक साधारण पायथन लिपि है, जो दिन का उपयोग करके बिंग फोटो खींचती है requests
और json
:
import requests
import json
BING_URI_BASE = "http://www.bing.com"
BING_WALLPAPER_PATH = "/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US"
# open the Bing HPImageArchive URI and ask for a JSON response
resp = requests.get(BING_URI_BASE + BING_WALLPAPER_PATH)
if resp.status_code == 200:
json_response = json.loads(resp.content)
wallpaper_path = json_response['images'][0]['url']
filename = wallpaper_path.split('/')[-1]
wallpaper_uri = BING_URI_BASE + wallpaper_path
# open the actual wallpaper uri, and write the response as an image on the filesystem
response = requests.get(wallpaper_uri)
if resp.status_code == 200:
with open(filename, 'wb') as f:
f.write(response.content)
else:
raise ValueError("[ERROR] non-200 response from Bing server for '{}'".format(wallpaper_uri))
else:
raise ValueError("[ERROR] non-200 response from Bing server for '{}'".format(BING_URI_BASE + BING_WALLPAPER_PATH))
यह एक फाइल TurtleTears_EN-US7942276596_1920x1080.jpg
को उसी डायरेक्टरी के रूप में लिखेगा जहां स्क्रिप्ट निष्पादित होती है। बेशक, यहां चीजों का एक पूरा गुच्छा ट्वीक कर सकता है, लेकिन काम आसानी से पूरा हो जाता है।
मैं आपको बताता हूँ कि कैसे जावास्क्रिप्ट और php का उपयोग करके दिन के दैनिक वॉलपेपर को काटें।
इस js कोड को आज़माएं:
<script>
fetch('https://techytricks97.000webhostapp.com/')
.then(response => response.text())
.then(text=>{document.body.style.background="url('"+text+"')";document.body.style.backgroundSize='cover';});
</script>
यह स्क्रिप्ट आपके HTML दस्तावेज़ की पृष्ठभूमि के रूप में दिन की दैनिक छवि को सेट करती है (आप इसे अपने उपयोग के अनुसार संशोधित कर सकते हैं)।
यह लिंक- https://techytricks97.000webhostapp.com दिन, दिन का बिंग वॉलपेपर देता है।
fetch()
आज की बिंग छवि का url प्राप्त करता है https://techytricks97.000webhostapp.com
और text=>{document.body.style.background="url('"+text+"')";document.body.style.backgroundSize='cover';}
इसे पृष्ठभूमि के रूप में सेट करता है।
नोट: Microsoft आपकी साइट की पृष्ठभूमि के रूप में दैनिक छवियों का उपयोग करने की अनुमति नहीं देता है, आप इसका उपयोग फ़ोन / डेस्कटॉप वॉलपेपर, या कॉपीराइट का उल्लेख करने के साथ अन्य चीजों पर कर सकते हैं।
यहाँ php कोड है जो http://techytricks97.000webhostapp.com पर उपयोग किया जाता है :
<?php
header('Access-Control-Allow-Origin: *');
ini_set('display_errors', 1);
$reg=file_get_contents('https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-IN');
$reg=json_decode($reg);
$meka=$reg->images[0]->url;
echo('http://www.bing.com'.$meka);
?>
आप http://techytricks97.000webhostapp.com
केवल उपयोग कर सकते हैं या अपने सर्वर पर अपनी स्वयं की php फ़ाइल सेटअप कर सकते हैं।
एक और नोट: मैंने केवल जावास्क्रिप्ट का उपयोग नहीं किया, क्योंकि ब्राउज़र की समान-मूल-नीति इसे प्रतिबंधित करती है, लेकिन मेरी php फ़ाइल से प्राप्त करने की अनुमति है जैसा मैंने डाला हैheader('Access-Control-Allow-Origin: *');
अपने php कोड में है। मैं एक और प्रॉक्सी का उपयोग कर सकता था लेकिन उनके पास उच्च ट्रैफ़िक है (मेरी साइट को शायद ही एक दिन में कोई क्लिक मिलता है)।
यदि आप किसी अन्य भाषा का उपयोग कर रहे हैं, तो आपको बस इस फाइल को पढ़ना होगा ( http://techytricks97.000webhostapp.com )
मुझे एक उचित RSS फ़ीड प्राप्त करने में समस्या हो रही थी जिसका उपयोग मैं जॉन के बैकग्राउंड स्विचर के साथ कर सकता था जब तक कि मुझे यह फीडबर्नर फीड नहीं मिला जो कि काफी अच्छी तरह से काम करता है: http://feeds.feedburner.com/bingimages
Github पर बिंग-डेस्कटॉप-वॉलपेपर-चेंजर पर एक नज़र डालें । स्क्रिप्ट अजगर में लिखी गई है और मुझे उम्मीद है कि आपको अपना जवाब मिल जाएगा।
#!/usr/bin/python
#-*- coding: utf-8 -*-
import os
import urllib
import urllib2
from bs4 import BeautifulSoup
# Get BingXML file which contains the URL of the Bing Photo of the day
# idx = Number days previous the present day. 0 means current day, 1 means yesterday, etc
# n = Number of images predious the day given by idx
# mkt denotes your location. e.g. en-US means United States. Put in your country code
BingXML_URL = "http://www.bing.com/HPImageArchive.aspx? format=xml&idx=0&n=1&mkt=en-US"
page = urllib2.urlopen(BingXML_URL)
BingXML = BeautifulSoup(page, "lxml")
# For extracting complete URL of the image
Images = BingXML.find_all('image')
ImageURL = "https://www.bing.com" + Images[0].url.text
ImageName = Images[0].startdate.text+".jpg"
urllib.urlretrieve(ImageURL, ImageName)
विस्तृत कोड के लिए Github परियोजना पर एक नज़र डालें
मैंने आखिरकार xml संग्रह से सबसे अधिक छवियां (16) प्राप्त करने के लिए पायथन 3 में एक स्क्रिप्ट लिखने का फैसला किया।
तो अब मैं बिना किसी प्रयास के चित्रों को संग्रहित कर सकता हूं। बस पायथन स्क्रिप्ट चलाएं।
मैं छवियों को वर्ष / माह के फ़ोल्डर में इस तरह व्यवस्थित करता हूं: 2018> 12 दिसंबर> 2018-12-06.jpg
यह स्क्रिप्ट मेरे बिंग वॉलपेपर फ़ोल्डर में जाती है। (जो मेरे चित्र फ़ोल्डर में है)
import urllib.request as urllib
import json
from datetime import date
from dateutil import parser
import sys,os
months = "January","Febuary","March","April","May","June","July","August","September","October","November","December"
def downloadBingImages(start):
try: data = urllib.urlopen("https://www.bing.com/hpimagearchive.aspx?format=js&idx=%i&n=8&mkt=en-NZ"%start).read()
except: sys.exit()
e = json.loads(data.decode())
images = e["images"]
for image in images:
d = parser.parse(image["startdate"]) # parse("20181206")
filename = str(d.date())+".jpg" # 2018-12-06.jpg
folder = "%i/%i %s/"%(d.year,d.month,months[d.month-1]) # 2018/12 December/
file = folder+filename # 2018/12 December/2018-12-06.jpg
if not os.path.exists(folder): os.makedirs(folder)
exists = os.path.isfile(file)
url = "https://www.bing.com"+image["urlbase"]+"_1920x1200.jpg"
print(("downloading","exists")[exists],filename,url)
if not exists:
try: urllib.urlretrieve(url,file)
except: sys.exit()
print()
# downloads the 16 latest bing images
downloadBingImages(-1)
downloadBingImages(7)
वॉलपेपर को अपडेट करने के लिए वैकल्पिक अतिरिक्त कोड: (डाउनलोड के नीचे रखेंबिमेज (7))
import ctypes,win32con
def getWallpaper():
ubuf = ctypes.create_unicode_buffer(512)
ctypes.windll.user32.SystemParametersInfoW(win32con.SPI_GETDESKWALLPAPER,len(ubuf),ubuf,0)
return ubuf.value
def setWallpaper(path):
changed = win32con.SPIF_UPDATEINIFILE | win32con.SPIF_SENDCHANGE
ctypes.windll.user32.SystemParametersInfoW(win32con.SPI_SETDESKWALLPAPER,0,path,changed)
# update wallpaper after a week from current
wallpaper = getWallpaper()
if wallpaper.startswith(os.getcwd()): # has to be in script directory
try: wallpaperDate = parser.parse(os.path.splitext(os.path.basename(wallpaper))[0])
except: sys.exit() # not using an image with a parsable date
t = date.today()
if (t-wallpaperDate.date()).days>=7: # been a week or longer
setWallpaper(os.path.abspath("%i/%i %s/"%(t.year,t.month,months[t.month-1])+str(t)+".jpg")) # .../2018/12 December/2018-12-14.jpg
उदाहरण आउटपुट:
exists 2018-12-15.jpg https://www.bing.com/az/hprichbg/rb/YosemiteBridge_ROW11493343707_1920x1200.jpg
exists 2018-12-14.jpg https://www.bing.com/az/hprichbg/rb/CardinalBerries_ROW13321753978_1920x1200.jpg
exists 2018-12-13.jpg https://www.bing.com/az/hprichbg/rb/ReykjavikYuleLads_ROW12406174277_1920x1200.jpg
exists 2018-12-12.jpg https://www.bing.com/az/hprichbg/rb/PoinsettiaBuds_ROW14015106672_1920x1200.jpg
exists 2018-12-11.jpg https://www.bing.com/az/hprichbg/rb/KilimanjaroMawenzi_ROW12001033920_1920x1200.jpg
exists 2018-12-10.jpg https://www.bing.com/az/hprichbg/rb/ChristmasIslandCrab_ROW12174154872_1920x1200.jpg
exists 2018-12-09.jpg https://www.bing.com/az/hprichbg/rb/JohnDaySnow_ROW10922424229_1920x1200.jpg
exists 2018-12-08.jpg https://www.bing.com/az/hprichbg/rb/BanffEvergreens_ROW13248925556_1920x1200.jpg
exists 2018-12-07.jpg https://www.bing.com/az/hprichbg/rb/TaisetsuShirakawago_ROW12053480529_1920x1200.jpg
exists 2018-12-06.jpg https://www.bing.com/az/hprichbg/rb/Huuhkajat_ROW11700922065_1920x1200.jpg
exists 2018-12-05.jpg https://www.bing.com/az/hprichbg/rb/SurfersBronteBeach_ROW9358782018_1920x1200.jpg
exists 2018-12-04.jpg https://www.bing.com/az/hprichbg/rb/SphinxObservatory_ROW9691446114_1920x1200.jpg
exists 2018-12-03.jpg https://www.bing.com/az/hprichbg/rb/HussarPoint_ROW8654856850_1920x1200.jpg
exists 2018-12-02.jpg https://www.bing.com/az/hprichbg/rb/Nuuk_ROW12381573676_1920x1200.jpg
exists 2018-12-01.jpg https://www.bing.com/az/hprichbg/rb/RedAntarctica_ROW12620598839_1920x1200.jpg
exists 2018-11-30.jpg https://www.bing.com/az/hprichbg/rb/KilchurnSky_ROW9474162800_1920x1200.jpg
पीएस उपरोक्त स्क्रिप्ट &mkt=en-NZ
न्यूजीलैंड छवियों के लिए उपयोग कर रहा है।
आप यहां अन्य देशों के लिए बाजार कोड देख सकते हैं ।
आप यहां विभिन्न देशों के लिए 2009 से संग्रहीत सभी छवियों को भी देख सकते हैं ।
(केवल 1366x768 में हालांकि)
लॉग इन करते समय चलाने के लिए मेजर PS टास्क शेड्यूलर में स्क्रिप्ट जोड़ते हैं। (या दैनिक / साप्ताहिक)
बेसिक टास्क
प्रोग्राम / स्क्रिप्ट बनाएं : अजगर (या C: \ Python34 \ python.exe यदि यह आपके env पथ में नहीं है)
तर्क: "पथ / to / your / script.py"
start: "path / to /"
अपडेट करें! (मार्च 2019)
2019-03-10 के लिए छवि को xml और rss प्रारूप दोनों में गलत शुरुआत (20190309) दी गई थी।
इसके बजाय Json प्रारूप का उपयोग करना। (चूंकि यह सटीक तारीख देता है)
https://peapix.com/bing/feed
बिंग लोगो के बिना नवीनतम बिंग छवि को सूचीबद्ध करेगा, peapix.com द्वारा बनाए रखेगा । निम्नलिखित देश / क्षेत्र का समर्थन किया: AU, CA, CN, DE, FR, JP, US, GB।
उदाहरण के लिए, के लिए https://peapix.com/bing/feed?country=jp जापान के लिए और https://peapix.com/bing/feed?country=us संयुक्त राज्य अमेरिका के लिए।
बैश एक लाइनर (जरूरत बैश, कर्ल और जॉक), एक क्रोनजोब में डालने के लिए उपयोगी:
BACKGROUND_META=$(curl 'https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US'); curl -o $(echo $BACKGROUND_META | jq -r '.images[0].urlbase' | sed s/.*=//).jpg "https://bing.com$(echo $BACKGROUND_META| jq -r '.images[0].url')"
आप उस url के file_content प्राप्त करने और छवि के लिए फ़ाइल खोजने पर विचार कर सकते हैं। यकीन नहीं है कि यह सबसे अच्छा तरीका है, लेकिन यह एक तरीका है।
@Siv से URL का उपयोग करते हुए, यहां जावास्क्रिप्ट का एक उदाहरण है जो अपडेट करता है <div class="bgimg" id="background">
function GetImageURL(ans) {
var suffix = ans.images[0].url
document.getElementById("background").style.backgroundImage = 'url("' +
'http://bing.com/' + suffix + '"'
}
function GetJSON() {
var xmlhttp = new XMLHttpRequest()
var url = "https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1"
xmlhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var ans = JSON.parse(this.responseText);
GetImageURL(ans);
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
window.onload = function () {
GetJSON()
}
इस वर्ग के लिए सीएसएस है:
.bgimg {
height: 100%;
position: relative;
opacity: 0.95;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
आप ऐसा कर सकते हैं कि एक अजगर मशीन पर अजगर और विग का उपयोग कर:
import os # import the os package
os.system("wget -O index.html http://www.bing.com") # download the bing index
str1 = open('index.html', 'r').read() # extract the file path using split
str2=str1.split("g_img={url: \"")[1]
str3=str2.split(".jpg")[0]
os.system("wget -O daily_im.jpg http://www.bing.com" + str3 + ".jpg") # donwload the daily image
यह स्थानीय निर्देशिका में daily_im.jpg नाम के तहत दैनिक बिंग पृष्ठभूमि को डाउनलोड करता है। आप सब कुछ एक स्क्रिप्ट-थ्रेड पर रख सकते हैं और इसे प्रोग्रामेटिक रूप से लॉन्च कर सकते हैं।
EDIT 09/27/2018: http://www.istartedsomething.com/bingimages सप्ताह के लिए 404 का जवाब देता है। यह अब मौजूद नहीं हो सकता है। :-(
आप istartedsomething.com के बिंग इमेज आर्काइव का उपयोग कर सकते हैं । यह एक अनौपचारिक बिंग इमेज आर्काइव है। यह एक घर का बना समापन बिंदु का उपयोग करता है जो छवियों को पुनः प्राप्त करने में सहायक होता है:
GET /bingimages/getimage.php?id=<image_id>
id
वह तार है जिसमें छवि प्रकाशित की गई थी और वह देश जहां यह प्रकाशित हुआ था। id
निम्नलिखित प्रारूप का अनुपालन करना होगा: YYYYMMDD-xx
जहां:
YYYY
वर्ष, चार अंकों के साथ लिखा जाता है।MM
वह महीना है, जिसे दो अंकों के साथ लिखा गया है।DD
वह दिन है, जिसे दो अंकों के साथ लिखा गया है।xx
देश सूचक है। वर्तमान में बिंग इमेज आर्काइव निम्नलिखित देशों का समर्थन करता है:
au
: ऑस्ट्रेलिया।br
: ब्राजील।ca
: कनाडा।cn
: चीन।de
: Deutschlandfr
: फ्रांस।gb
: ग्रेट ब्रिटेन।jp
: जापान।nz
: न्यूजीलैंड।uk
: यूनाइटेड किंगडम।us
: संयुक्त राज्य अमरीका।यह एक उपयोगी JSON ऑब्जेक्ट देता है यदि इसके पास कुछ जानकारी है या गलत है अगर यह कुछ भी नहीं मिला है।
उदाहरण 1: बिंग दैनिक छवि को पुनर्प्राप्त करना जो मई 24, 2014 को न्यूजीलैंड में प्रकाशित हुआ था
छवि आईडी 20140524-nz
इसलिए है क्योंकि मांग की गई छवि 05/24/2014 को प्रकाशित हुई थी और यह न्यूजीलैंड में प्रकाशित हुई थी, जिसका देश सूचक है nz
।
http://www.istartedsomething.com/bingimages/getimage.php?id=20140524-nz JSON का निम्नलिखित टुकड़ा लौटाता है:
{
"url":"\/az\/hprichbg\/rb\/LakeMagadiFlamingos_ROW9792683076_1366x768.jpg",
"region":"nz",
"date":"2014-05-24",
"copyright":"Flamingos take flight, Lake Magadi, Kenya (\u00a9 Bobby Haas\/Getty Images)(Bing New Zealand)",
"imageurl":"http:\/\/www.istartedsomething.com\/bingimages\/cache\/LakeMagadiFlamingos_ROW9792683076_1366x768.jpg",
"hotspots":[],
"video":[]
}
अपनी छवि प्राप्त करने के लिए आप imageurl
फ़ील्ड या url
(बिंग URL पथ) फ़ील्ड का उपयोग कर सकते हैं ।
उदाहरण 2: बिंग दैनिक छवि को पुनर्प्राप्त करना जो फ्रांस में जुलाई, 12 वीं 1998 को प्रकाशित हुआ था
छवि आईडी 19980712-fr
इसलिए है क्योंकि मांग की गई छवि 07/12/1998 को प्रकाशित हुई थी और यह फ्रांस में प्रकाशित हुई थी, जिसका देश सूचक है fr
।
http://www.istartedsomething.com/bingimages/getimage.php?id=19980712-fr रिटर्न false
क्योंकि 07/12/1998 को फ्रांस के लिए कोई बिंग डेली इमेज नहीं है (बिंग इस समय भी मौजूद नहीं था)।
ओपी ऑपरेटिंग सिस्टम को निर्दिष्ट नहीं करता है, इसलिए यहां लिनक्स में उपयोग के लिए एक है। मैंने यहां दी गई स्क्रिप्ट से संशोधित किया ।
मूल रूप से यह दिन की छवि के url को प्राप्त करता है, छवि को डाउनलोड करता है और एक निश्चित फ़ाइल में सहेजता है ~/.config/wallpaper.jpg
, और feh
वॉलपेपर सेट करने के लिए उपयोग करता है। उसी समय एक अधिसूचना भेजता है।
#!/bin/sh
WP_FILE=$HOME/.config/wallpaper.jpg
bing="www.bing.com"
# $xmlURL is needed to get the xml data from which
# the relative URL for the Bing pic of the day is extracted
#
# The mkt parameter determines which Bing market you would like to
# obtain your images from.
# Valid values are: en-US, zh-CN, ja-JP, en-AU, en-UK, de-DE, en-NZ, en-CA or opted out.
#
# The idx parameter determines where to start from. 0 is the current day,
# 1 the previous day, etc.
xmlURL="http://www.bing.com/HPImageArchive.aspx?format=xml&idx=0&n=1&mkt=en-US"
# The desired Bing picture resolution to download
# Valid options: "_1024x768" "_1280x720" "_1366x768" "_1920x1200"
desiredPicRes="_1920x1080"
# The file extension for the Bing pic
picExt=".jpg"
# Extract the relative URL of the Bing pic of the day from
# the XML data retrieved from xmlURL, form the fully qualified
# URL for the pic of the day, and store it in $picURL
# Form the URL for the desired pic resolution
desiredPicURL=$bing$(curl -s $xmlURL | grep -oP "(?<=<urlBase>)(.*?)(?=</urlBase>)")$desiredPicRes$picExt
# Form the URL for the default pic resolution
defaultPicURL=$bing$(curl -s $xmlURL | grep -oP "(?<=<url>)(.*?)(?=</url>)")
# $picName contains the filename of the Bing pic of the day
# Attempt to download the desired image resolution. If it doesn't
# exist then download the default image resolution
if wget --quiet --spider "$desiredPicURL"
then
# Download the Bing pic of the day at desired resolution
curl -s -o "$WP_FILE" "$desiredPicURL"
else
# Download the Bing pic of the day at default resolution
curl -s -o "$WP_FILE" "$defaultPicURL"
fi
if [[ -f "${WP_FILE}" ]]; then
feh --bg-scale "$WP_FILE" && \
notify-send -i emblem-photos "Wallpaper" "Wallpaper changed" \
-h int:suppress-sound:1 -h int:transient:1
fi