Created
January 16, 2014 18:24
-
-
Save benburry/8460394 to your computer and use it in GitHub Desktop.
Try to work out if AirBnB listings still exists from its url
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
#!/usr/bin/env python | |
import requests | |
import sys | |
import time | |
import re | |
PAT = re.compile(r'^https?://(?:w{3}\.)?airbnb\..*/([^/]+)/?$') | |
def try_airbnb(url, exclude=False): | |
m = PAT.match(url) | |
if m: | |
r = requests.get(url) | |
if r.status_code == requests.codes.ok and r.url.endswith(m.group(1)): | |
print url | |
elif not exclude: | |
print '~~%s~~' % url | |
if __name__ == '__main__': | |
exclude = (len(sys.argv) > 1 and sys.argv[1] == '-e') | |
try: | |
for line in sys.stdin: | |
line = line.strip() | |
if line: | |
time.sleep(0.2) # bless | |
try_airbnb(line, exclude=exclude) | |
except KeyboardInterrupt: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cat list_of_airbnb_urls | ./try_airbnb.py