Question

I have to import EPF data from itunes Store daily so i have to write a script which will authenticate me firstly through the feeds url and then allow me to download the file automatically through script.

But, i am not finding any way to authenticate myself through url:

http://feeds.itunes.apple.com/feeds/

firstly i downloaded it manually but now i want my script to download it daily. How i can authenticate myself for this? Or there is any other way to achieve this?

Any ideas or view will be highly appreciated.

Était-ce utile?

La solution

I did it through curl and now i am in it.

$username = "username";
$password = "password";
$url = "http://feeds.itunes.apple.com/feeds/";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;

it was this much simple :)

Autres conseils

In python you could use the requests library for example, that does Auth nicely (and you could write your download logic maybe in an easier fashion. It would look like something like this

username='yourusernamehere'
password='yourpasswordhere'
response = requests.get('https://feeds.itunes.apple.com/feeds/', auth=(username, password), stream=True)

Note that I used the stream=True mechanism because you will be downloading huge files that probably will not fit in memory, you should use chunking like so:

 with open(local_filename, 'wb') as f:
    for chunk in response.iter_content(chunk_size=1024):
        if chunk:  # filter out keep-alive new chunks
            f.write(chunk)
            f.flush()
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top