Last active
February 7, 2018 15:53
-
-
Save recoder/d0686112d826dbe57128c721a1389fce to your computer and use it in GitHub Desktop.
Python script to extract all external links for archiving
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/python | |
# LJ links extractor | |
# (c) 2018 by ReCoder (recoder.livejournal.com) | |
import argparse | |
import datetime | |
import urllib, urlparse | |
from lj import lj | |
from BeautifulSoup import BeautifulSoup | |
parser = argparse.ArgumentParser(description='Process some integers.') | |
parser.add_argument('--username', help='LJ username') | |
parser.add_argument('--password', help='LJ password') | |
args = parser.parse_args() | |
ljclient = lj.LJServer("Python-LJlinks/1.0", "http://recoder.livejournal.com/tag/nexvs; recoder@gmail.com") | |
ljclient.login(args.username, args.password) | |
events = ljclient.getevents_lastn(before=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) | |
links = set() | |
for e in events['events']: | |
soup = BeautifulSoup(str(e['event'])) | |
for link in soup.findAll('a'): | |
links.add(link.get('href')) | |
for link in links: | |
o = urlparse.urlparse(link) | |
o = o._replace(path=urllib.quote(o.path.encode('cp1251'))) | |
print urlparse.urlunparse(o) | |
# usage: for u in `ljlinks.py --username {username} --password {password}`; do archivenow --is --ia $u; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment