Skip to content

Instantly share code, notes, and snippets.

@datamafia
Created March 26, 2014 00:34
Show Gist options
  • Save datamafia/9774592 to your computer and use it in GitHub Desktop.
Save datamafia/9774592 to your computer and use it in GitHub Desktop.
Waiting for the Bitwig - send DM to my Twitter account on change
#!/usr/bin/env python
import urllib2
import time
class bitwig:
running = None
last_size = 0
def __init__(self):
if not self.running:
self.running = 1
while 1 == 1 :
self.run()
time.sleep(10) # pause 10 sec
def run(self):
response = urllib2.urlopen('http://www.bitwig.com/en/bitwig-studio') #target url
html = response.read()
sz = len(html)
print str(sz)
if sz != self.last_size: # reminder : will send a DM on start up
print 'from '+ str(self.last_size) + ' to ' + str(sz)
msg = str(self.last_size) + '-' + str(sz)
self.last_size = sz
response = urllib2.urlopen('http://localhost:3000/test/omnimono/'+msg) #local rails app sends me DM in twitter
go = bitwig()
@fletom
Copy link

fletom commented May 19, 2014

To give you an idea of how this would be written in more idiomatic Python:

#!/usr/bin/env python
import urllib2
import time

def check_size():
    return len(urllib2.urlopen('http://www.bitwig.com/en/bitwig-studio').read())

if __name__ == '__main__':
    size = last_size = check_size()
    while True:
        size, last_size = check_size(), size
        if size != last_size:
            urllib2.urlopen('http://localhost:3000/test/omnimono/{}-{}'.format(size, last_size))
        time.sleep(10)

@datamafia
Copy link
Author

Thx, I wrote this fast and cheap. Much tighter!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment