Last active
March 16, 2017 12:40
-
-
Save rodfersou/8797a5d2fc92b1312789e71217fe4f2e to your computer and use it in GitHub Desktop.
Import ssh configs from digital ocean
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
# -*- coding: utf-8 -*- | |
from glob import glob | |
from itertools import izip | |
from lxml import html | |
# elements by CSS class; http://stackoverflow.com/a/1604480 | |
CLASS_SELECTOR = '//*[contains(concat(" ", normalize-space(@class), " "), " {0} ")]' | |
TEMPLATE = ''' | |
Host {title}_ | |
HostName {ip} | |
User rodfersou | |
Port 2233 | |
LocalForward 0.0.0.0:8180 localhost:8080 | |
LocalForward 0.0.0.0:8181 localhost:8081 | |
LocalForward 0.0.0.0:8182 localhost:8082 | |
LocalForward 0.0.0.0:8183 localhost:8083 | |
LocalForward 0.0.0.0:8184 localhost:8084 | |
LocalForward 0.0.0.0:8188 localhost:8088 | |
LocalForward 0.0.0.0:8189 localhost:8089 | |
LocalForward 0.0.0.0:8190 localhost:80 | |
LocalForward 0.0.0.0:8191 localhost:6081 | |
LocalForward 0.0.0.0:8192 localhost:9080 | |
IdentityFile ~/.ssh/ids/000_rodfersou | |
Host {title}__ | |
HostName {ip} | |
User rodfersou | |
Port 2233 | |
LocalForward 0.0.0.0:8280 localhost:8080 | |
LocalForward 0.0.0.0:8281 localhost:8081 | |
LocalForward 0.0.0.0:8282 localhost:8082 | |
LocalForward 0.0.0.0:8283 localhost:8083 | |
LocalForward 0.0.0.0:8284 localhost:8084 | |
LocalForward 0.0.0.0:8288 localhost:8088 | |
LocalForward 0.0.0.0:8289 localhost:8089 | |
LocalForward 0.0.0.0:8290 localhost:80 | |
LocalForward 0.0.0.0:8291 localhost:6081 | |
LocalForward 0.0.0.0:8292 localhost:9080 | |
IdentityFile ~/.ssh/ids/000_rodfersou | |
Host {title} | |
HostName {ip} | |
User rodfersou | |
Port 2233 | |
IdentityFile ~/.ssh/ids/000_rodfersou | |
''' | |
for name in glob('do/*.html'): | |
el = html.parse(name) | |
titles = el.xpath(CLASS_SELECTOR.format('Resource-title')) | |
titles = [title.text.strip().split('.')[0] for title in titles] | |
ips = el.xpath(CLASS_SELECTOR.format('ip') + CLASS_SELECTOR.format('click-to-copy-text')) | |
ips = [ip.text.strip() for ip in ips] | |
for title, ip in izip(titles, ips): | |
f = open('../config.d/{0}'.format(title), 'w') | |
f.write(TEMPLATE.format(title=title, ip=ip)) | |
f.close() |
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
#!/bin/bash | |
cd import | |
python import.py | |
cd .. | |
cat config.d/* > config |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
.ssh/update.sh
.ssh/import/import.py
.ssh/import/do/page_saved_from_do.html
.ssh/config.d/generated_files
.ssh/config/ids/id_files