Automatizando la generación de Datawarehouses a través de metadatos
Automatizando tarefas com Python
-
Upload
pugpe -
Category
Technology
-
view
2.237 -
download
10
Transcript of Automatizando tarefas com Python
Lightning TalkUsing Python to Automate Repetitive Tasks
André EricsonNovembro/2011, Pug-Pe
Using Python to AutomateRepetitive TasksRoteiro
• Por que py?• Case of Study 1
• Motivação• Objetivos• Ferramentas
• Case of Study 2• Motivação• Objetivos• Resultados• Ferramentas
• Code• Bonus
Por que Python?
• Simplicidade• Legibilidade do Código• Tempo• Batteries Included• PyPI(17484 packages)
• Não é Java
Por que Python?
• Simplicidade• Legibilidade do Código• Tempo• Batteries Included• PyPI(17484 packages)• Não é Java
Case of Study: Unicap_br
Motivação
Unicap-brObjetivos
• Fazer o login no site da católica• Receber dados dos livros emprestados• Renovar livros• Checar sucesso da renovação• Renovar automaticamente com frequência Crontab
Unicap-brObjetivos
• Fazer o login no site da católica• Receber dados dos livros emprestados• Renovar livros• Checar sucesso da renovação• Renovar automaticamente com frequência Crontab
Unicap-brObjetivos
• Fazer o login no site da católica• Receber dados dos livros emprestados• Renovar livros• Checar sucesso da renovação• Renovar automaticamente com frequência Crontab
Unicap-brObjetivos
• Fazer o login no site da católica• Receber dados dos livros emprestados• Renovar livros• Checar sucesso da renovação• Renovar automaticamente com frequência Crontab
Unicap-brObjetivos
• Fazer o login no site da católica• Receber dados dos livros emprestados• Renovar livros• Checar sucesso da renovação• Renovar automaticamente com frequência Crontab
Unicap-brFerramentas
• BeautifulSoup: HTML/XML parser designed for quick turnaroundprojects like screen-scraping
• Mechanize: Stateful programmatic web browsing in Python
Unicap-brFerramentas
• BeautifulSoup: HTML/XML parser designed for quick turnaroundprojects like screen-scraping
• Mechanize: Stateful programmatic web browsing in Python
Case of Study: CheckSubs
Motivação
Objetivo
• Checar legendas novas para determinadas séries de TV• Notificar quando uma nova legenda estiver disponível.
Objetivo
• Checar legendas novas para determinadas séries de TV• Notificar quando uma nova legenda estiver disponível.
Resultado
Ferramentas
• Python-twitter: A Python wrapper around the Twitter API• bitlyapi: A very thin wrapper for the bit.ly API• pynotify: Python bindings for libnotify(Desktop Notification Library)• feedparser: Parse Atom and RSS feeds in Python
Ferramentas
• Python-twitter: A Python wrapper around the Twitter API• bitlyapi: A very thin wrapper for the bit.ly API• pynotify: Python bindings for libnotify(Desktop Notification Library)• feedparser: Parse Atom and RSS feeds in Python
Ferramentas
• Python-twitter: A Python wrapper around the Twitter API• bitlyapi: A very thin wrapper for the bit.ly API• pynotify: Python bindings for libnotify(Desktop Notification Library)• feedparser: Parse Atom and RSS feeds in Python
Ferramentas
• Python-twitter: A Python wrapper around the Twitter API• bitlyapi: A very thin wrapper for the bit.ly API• pynotify: Python bindings for libnotify(Desktop Notification Library)• feedparser: Parse Atom and RSS feeds in Python
Talk is cheap.Showme the Code.
BeautifulSoup
1 <tr class=’rel2’>2 <td nowrap><input type=’checkbox’3 name=’check_2’ value=’99236167@#1’>4 </td>5 <td nowrap>99236167</td>6 <td nowrap>7 Introducao a administracao:8 edicao compacta.</td>9 <td nowrap> </td>10 <td nowrap>Livros</td>11 <td nowrap>25/10/2011</td>12 <td nowrap>09/11/2011</td>13 <td nowrap> </td>14 <td nowrap> </td>15 <td nowrap>Normal</td>16 <td nowrap>Biblioteca Central</td>17 <td nowrap>0</td>18 <td nowrap>15</td>19 </tr>
1 soup = BeautifulSoup(request)2 books = soup.findAll(’tr’, attrs={’class’:3 re.compile(’rel.*’)})4 return [Book(book) for book in books]5 ############################################6 class Book(object):7 def __init__(self, soup_tag):8 tds = soup_tag.findAll(’td’)9 self.check = str(tds[0].find(’input’)10 [’name’])11 self.title = tds[2].string.strip()
Mechanize
1 <form ... name="form1" ... >2 <input type="text" name="login">3 <input type=’password’ name=’password’>4 </form>
1 browser = mechanize.Browser()2 cj = cookielib.LWPCookieJar()3 browser.set_cookiejar(cj)4 browser.open(LOGIN_PAGE)5 browser.select_form(name=’form1’)6 browser.form[’login’] = login7 browser.form[’password’] = password8 r = browser.submit()
Android(SL4A)
Android(SL4A)
Tasker