This Python script uses Digital Ocean api services. Importing the features from the Python module digitalocean. Data is pulled and edited.
Here is a list of features and ideas.
Plans start as little as $5.00 a month. Servers are charged per the hour. Digital Ocean
In [1]:
import os
import json
import digitalocean
In [9]:
opcli = open('passwd', 'r')
opapi = open('passap', 'r')
In [7]:
digclip = str(opcli.read())
In [10]:
digcli = str(opapi.read())
In [6]:
manager = digitalocean.Manager(client_id = digcli, api_key = apikey)
In [7]:
mydrop = manager.get_all_droplets()
In [8]:
print mydrop
In [9]:
dropo = mydrop[0]
In [10]:
print dropo
In [11]:
events = dropo.get_events()
In [34]:
for event in events:
event.load()
print event.percentage
In [35]:
servlis = []
In [75]:
meip.keys
In [88]:
for meip in mydrop:
print meip.name
servlis.append(meip.name)
print meip.ip_address
servlis.append(meip.ip_address)
print meip.status
servlis.append(meip.status)
print meip.image_id
servlis.append(meip.image_id)
servlis.append('wcmckee')
servlis.append(meip.region_id)
In [92]:
servlis.sort()
In [94]:
fservlz = list(set(servlis))
In [96]:
fservlz.sort()
In [97]:
fservlz
Out[97]:
In [98]:
from crontab import CronTab
In [99]:
syscrm = CronTab()
In [111]:
job = syscrm.new(command='cd learnpython; ipython notebook --profile=wcm')
In [112]:
job.every_reboot()
Out[112]:
In [113]:
job.enable()
Out[113]:
In [117]:
job.frequency_per_day()
Out[117]:
In [ ]:
clisz = []
In [129]:
svex = ia.search_movie('game of thrones')
In [175]:
thrlis = []
In [176]:
for sc in svex:
#print sc
#print sc[u'title']
#thrlis.append(sc[u'long imdb title'])
#thrlis.append(sc.get_current_info)
print sc.getID()
thrlis.append(sc.getID())
In [177]:
mov = ia.get_movie(thrlis[0])
In [179]:
mov.guessLanguage()
Out[179]:
In [189]:
cast = mov['cast'][0]
In [192]:
ia.update(cast)
In [193]:
cast[u'name']
Out[193]:
In [196]:
cast.notes
Out[196]:
In [209]:
cast.items()
Out[209]:
In [211]:
imghed = cast['headshot']
In [212]:
from IPython.display import Image
In [214]:
Image(imghed)
Out[214]:
In [205]:
cast.summary()
Out[205]:
In [200]:
for caz in cast.current_info:
print caz
In [202]:
cast.current_info[0]
Out[202]:
In [183]:
thrlis
Out[183]:
In [160]:
svex
Out[160]:
In [120]:
dex = ia.get_character('dexter')
In [119]:
from imdb import IMDb
ia = IMDb()
the_matrix = ia.get_movie('0133093')
print the_matrix['director']
for person in ia.search_person('Mel Gibson'):
print person.personID, person['name']
In [93]:
servlis
Out[93]:
In [84]:
olis = ['name', 'ip', 'status', 'id', 'user'] * 3
In [85]:
dictac = zip(olis, servlis)
In [86]:
dictac
Out[86]:
when converting to a dict why does it only take the first part of dictac.
In [73]:
dicza = dict(dictac)
In [74]:
dicza
Out[74]:
In [64]:
jsndigoc = json.dumps(dicza)
In [66]:
jsndigoc
Out[66]:
In [67]:
digocz = open('/home/will/Desktop/brobeur-static/feeds/digocserv.json', 'w')
In [68]:
digocz.write(jsndigoc)
In [69]:
digocz.close()
In [42]:
servlis
Out[42]:
In [43]:
dropo.ip_address
Out[43]:
In [44]:
dropo.name
Out[44]:
In [45]:
dropo
Out[45]:
In [46]:
droplis = []
In [47]:
iplis = []
In [48]:
dropdict = dict{}
In [49]:
drstr = []
In [50]:
for dr in mydrop:
print dr.ip_address
droplis.append(dr.name)
droplis.append(dr.ip_address)
iplis.append(dr.ip_address)
droplis.append(dr.status)
print dr.status
droplis.append(dr.region_id)
print dr.region_id
droplis.append(dr.ssh_key_ids)
droplis.append(dr.id)
droplis.append(dr)
print dr.name
print dr.ssh_key_ids
print dr.id
print dr.image_id
print dr
drstr.append(dr)
In [51]:
print droplis
In [52]:
print drstr
In [53]:
print iplis
In [54]:
#!/usr/bin/python
# All SSH libraries for Python are junk (2011-10-13).
# Too low-level (libssh2), too buggy (paramiko), too complicated
# (both), too poor in features (no use of the agent, for instance)
# Here is the right solution today:
import subprocess
import sys
HOST= '74.50.51.32'
# Ports are handled in ~/.ssh/config since we use OpenSSH
COMMAND="uname -a"
ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND],
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
result = ssh.stdout.readlines()
if result == []:
error = ssh.stderr.readlines()
print >>sys.stderr, "ERROR: %s" % error
else:
print result
In [55]:
pwd
Out[55]:
In [40]:
from crontab import CronTab
system_cron = CronTab()
system_cron.new
Out[40]:
In [50]:
dropo.api_key
Out[50]:
In [51]:
dropo.call_reponse
In [52]:
dropo.image_id
Out[52]:
In [53]:
dropo.size_id
Out[53]:
In [54]:
dropo.events
Out[54]:
In [55]:
dropo.size_id
Out[55]:
In [56]:
domain = manager.get_all_domains
In [57]:
print domain
In [58]:
domain.im_self
Out[58]:
In [59]:
gimg = manager.get_global_images
In [60]:
gimg
Out[60]:
In [61]:
list(gimg)
In [96]:
mysnap = manager.get_my_images()
In [97]:
my_droplets = manager.get_all_droplets()
In [98]:
for snap in mysnap:
print snap.name
print snap.id
In [73]:
my_droplets = manager.get_all_droplets()
for droplet in my_droplets:
print droplet
droplet.power_off()
In [46]:
for droplet in my_droplets:
print droplet
droplet.power_on()
In [64]:
for droplet in my_droplets:
print droplet
print droplet.name
In [54]:
dropo.power_off()
In [74]:
dropo.take_snapshot('deb')
In [82]:
dropo.status
Out[82]:
In [75]:
dropo.rebuild()
In [55]:
droplet.client_id
Out[55]:
In [67]:
myderp = manager.get_all_regions()
In [68]:
print myderp
In [69]:
myderp
Out[69]:
In [70]:
for derp in myderp:
print derp
droplis.append(derp.name)
droplis.append(derp.id)
print derp.name
print derp.id
In [72]:
print droplis
In [102]:
dropserv = digitalocean.Droplet(client_id=digcli, api_key=apikey, name = 'uburub', region_id=5, image_id=3137635, size_id=66, backup_active=False)
#dropserv.create()
dropserv.Droplet
In [ ]: