Last active
August 29, 2015 13:57
-
-
Save simonw/9572222 to your computer and use it in GitHub Desktop.
Our pixstar album frame stopped automatically refreshing (it's meant to pull our PhotoRSS feed every 6 hours), so I wrote a script to click the "refresh" button.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
1. GET | |
extract csrf token <input type='hidden' name='csrfmiddlewaretoken' value='1RNvCJoYdwKwtoOAd7kM73sBKJxhzN50' /> | |
2. POST https://www.pix-star.com/accounts/login/ | |
next:/ | |
username:... | |
password:... | |
csrfmiddlewaretoken:1RNvCJoYdwKwtoOAd7kM73sBKJxhzN50 | |
- keep the cookies | |
3. POST album ID to https://www.pix-star.com/album/is2/downloading2/ | |
""" | |
PIXSTAR_USERNAME = '' | |
PIXSTAR_PASSWORD = '' | |
ALBUM_ID = '1350472' | |
import requests | |
import re | |
import time | |
csrf_re = re.compile("<input type='hidden' name='csrfmiddlewaretoken' value='(\w+)' />") | |
def login_and_refresh(): | |
s = requests.Session() # To preserve cookies | |
response = s.get('https://www.pix-star.com/') | |
csrf_token = csrf_re.search(response.content).group(1) | |
time.sleep(1) | |
# Perform the login | |
response = s.post('https://www.pix-star.com/accounts/login/', { | |
'next': '/', | |
'username': PIXSTAR_USERNAME, | |
'password': PIXSTAR_PASSWORD, | |
'csrfmiddlewaretoken': csrf_token, | |
}) | |
time.sleep(1) | |
# Hit the refresh button | |
response = s.post('https://www.pix-star.com/album/is2/downloading2/', { | |
'album_id': ALBUM_ID, | |
'old_number': '100', # Required argument for some reason | |
}) | |
print response.content |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment