Last active
August 29, 2015 14:20
-
-
Save underr/695431a06333fb6341bd to your computer and use it in GitHub Desktop.
Client CLI para o cvip.ga
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/python3 | |
# -*-coding:utf-8 -* | |
"""Usage: | |
cvip.py list | |
cvip.py board <board> | |
cvip.py thread <board> <thread> | |
cvip.py post <board> <thread> <post> | |
cvip.py new <board> <title> <text> | |
cvip.py -h | --help | --version | |
""" | |
from docopt import docopt | |
from json import loads | |
import re, html, requests | |
cvip = 'http://cvip.ga' | |
arguments = docopt(__doc__, version='1.0.0') | |
if arguments['list']: | |
r = requests.get(cvip + '/board/') | |
boards = loads(r.text) | |
for board in boards: | |
print(" \033[95m»\033[0m \033[32m/%s/\033[0m — %s" % (board['slug'], board['title'])) | |
if arguments['board']: | |
board = arguments['<board>'] | |
r = requests.get(cvip + '/board/' + board) | |
threads = loads(r.text) | |
for thread in threads: | |
p = str(thread['post_count']) | |
print(" %s \033[95m»\033[0m \033[32m%s\033[0m (%s)" % (str(thread['id']), thread['title'], p)) | |
if arguments['thread']: | |
board = arguments['<board>'] | |
thread_n = arguments['<thread>'] | |
r = requests.get(cvip + '/board/' + board + '/thread/' + thread_n + '.json') | |
posts = loads(r.text) | |
for post in posts: | |
scp = html.unescape(post['comment']) # transforma ǎ em \u01ce | |
bl = scp.replace('<br>', '\n') # adiciona quebras de linhas | |
clear = re.sub('<[^<]+?>', '', bl) # remove tags <html> | |
print("%s \033[31m%s\033[0m " % (post['num'], 'VIPPER')) | |
print(clear + "\n") | |
if arguments['post']: | |
board = arguments['<board>'] | |
thread = arguments['<thread>'] | |
post = arguments['<post>'] | |
post_params = {'comment': post, 'board': board, 'thread': thread} | |
r = requests.post(cvip + '/post', params=post_params) | |
if r.status_code == 200: | |
print('Grande sucesso!') | |
else: | |
print('Erro ao enviar post') | |
if arguments['new']: | |
board = arguments['<board>'] | |
text= arguments['<text>'] | |
title = arguments['<title>'] | |
post_params = {'title': title, 'comment': text, 'board': board} | |
r = requests.post(cvip + '/post', params=post_params) | |
if r.status_code == 200: | |
print('Grande sucesso!') | |
else: | |
print('Erro ao enviar post') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment