1 Star 0 Fork 1

DeppWang/cloudnote

forked from vintnee/cloudnote 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
AuthorizeWidget.py 2.39 KB
一键复制 编辑 原始数据 按行查看 历史
倪文显 提交于 2017-05-02 17:02 . version 0.0.1
#! /usr/bin/python
#encoding=utf-8
#author: fakir
import oauth2 as oauth
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
from config import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWebKit import *
from PyQt5.QtNetwork import *
class AuthorizeWidget(QDialog):
def __init__(self, authorize_url, parent=None):
QDialog.__init__(self, parent)
self.authorize_url = authorize_url
self.setWindowTitle(APP_NAME)
self.layout = QHBoxLayout()
self.webView = QWebView(self)
self.layout.addWidget(self.webView)
self.layout.setSpacing(0)
self.layout.setMargin(0)
self.setLayout(self.layout)
self.setFixedWidth(290)
self.setFixedHeight(290)
self.verifier = ""
def loadAuthorize(self):
self.webView.load(QUrl(self.authorize_url))
self.connect(self.webView, SIGNAL("loadFinished(bool)"), self.loadFinished)
def loadFinished(self, finished):
frame = self.webView.page().currentFrame()
url = frame.url().toString()
print "url: ", url
doc = frame.documentElement()
if url.startsWith("http://account.youdao.com/login"): #初始登陆界面
doc.findFirst("div[id=t]").removeFromDocument()
doc.findFirst("div[id=b]").removeFromDocument()
doc.findFirst("div[class=login_left]").removeFromDocument()
content = doc.findFirst("div[id=login]")
content.setStyleProperty("position", "fixed")
content.setStyleProperty("width", "100px")
content.setStyleProperty("padding", "0px")
login = doc.findFirst("div[class=login_right]")
login.setStyleProperty("float", "none")
elif url.startsWith("http://note.youdao.com/oauth/authorize_handler"): #登陆成功确认界面
doc.findFirst("button[id=auth-btn]").evaluateJavaScript("this.click()")
elif url == "http://note.youdao.com/oauth/authorize":
text = doc.toPlainText()
print "text: ", text
reg = QRegExp("[0-9]{4,}")
pos = reg.indexIn(text, 0)
if pos != -1:
self.verifier = str(reg.cap(0))
self.close()
@staticmethod
def getVerifier(url):
w = AuthorizeWidget(url)
w.loadAuthorize()
w.exec_()
return w.verifier
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/DeppWXQ/cloudnote.git
git@gitee.com:DeppWXQ/cloudnote.git
DeppWXQ
cloudnote
cloudnote
master

搜索帮助