过了那么多年,我的接口还没抓完 (;¬_¬) ,没想到网易博客竟然主动死了( ̄. ̄)。。。。
之前网易博客的导出xml功能是需要开通会员才可以使用的,现在,免费啦!!!
三年前挖的坑,是时候填一下了。。。。
步骤大概是这样的
从网易那导出xml,然后写个脚本,导入到blogspot;
原来自打网易倒闭之后,事情变得那么简单。。。。
其中第一步导出xml有现成的地址,第三步导入blogspot三年前就通了,三年来运转良好。。。。
那么,就差第二步的脚本了。
2021年01月08日18:27:10
又过了两年。。。。
打算把这个坑填一下。。。。
然后打算用Python来干这事,毕竟Python学了那么多年,已经忘干净了还没用到。。。。
找了下现在有了现成的blogspot api
api 地址 developers.google.com/blogger/docs/3.0/reference/
还有了现成的github库 github.com/googleapis/google-api-python-client
感觉很简单了呢
确定本机python版本
SENRSL:Downloads senrsl$ python --version
Python 2.7.16
SENRSL:Downloads senrsl$ python2 --version
Python 2.7.16
SENRSL:Downloads senrsl$ python3 --version
Python 3.8.2
SENRSL:Downloads senrsl$
看起来以前写啥玩意的时候都安过。。。。
但是 pip3却没安装。
卸载重装Python3
SENRSL:Downloads senrsl$ brew uninstall --ignore-dependencies python3
Traceback (most recent call last):
10: from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in `<main>'
9: from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in `require_relative'
8: from /usr/local/Homebrew/Library/Homebrew/global.rb:28:in `<top (required)>'
7: from /usr/local/Homebrew/Library/Homebrew/global.rb:28:in `require'
6: from /usr/local/Homebrew/Library/Homebrew/os.rb:3:in `<top (required)>'
5: from /usr/local/Homebrew/Library/Homebrew/os.rb:21:in `<module:OS>'
4: from /usr/local/Homebrew/Library/Homebrew/os/mac.rb:58:in `prerelease?'
3: from /usr/local/Homebrew/Library/Homebrew/os/mac.rb:24:in `version'
2: from /usr/local/Homebrew/Library/Homebrew/os/mac.rb:24:in `new'
1: from /usr/local/Homebrew/Library/Homebrew/os/mac/version.rb:26:in `initialize'
/usr/local/Homebrew/Library/Homebrew/version.rb:368:in `initialize': Version value must be a string; got a NilClass () (TypeError)
SENRSL:Downloads senrsl$ brew --version
Traceback (most recent call last):
10: from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in `<main>'
9: from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in `require_relative'
8: from /usr/local/Homebrew/Library/Homebrew/global.rb:28:in `<top (required)>'
7: from /usr/local/Homebrew/Library/Homebrew/global.rb:28:in `require'
6: from /usr/local/Homebrew/Library/Homebrew/os.rb:3:in `<top (required)>'
5: from /usr/local/Homebrew/Library/Homebrew/os.rb:21:in `<module:OS>'
4: from /usr/local/Homebrew/Library/Homebrew/os/mac.rb:58:in `prerelease?'
3: from /usr/local/Homebrew/Library/Homebrew/os/mac.rb:24:in `version'
2: from /usr/local/Homebrew/Library/Homebrew/os/mac.rb:24:in `new'
1: from /usr/local/Homebrew/Library/Homebrew/os/mac/version.rb:26:in `initialize'
/usr/local/Homebrew/Library/Homebrew/version.rb:368:in `initialize': Version value must be a string; got a NilClass () (TypeError)
SENRSL:Downloads senrsl$ brew update-reset
==> Fetching /usr/local/Homebrew...
remote: Enumerating objects: 9208, done.
remote: Counting objects: 100% (9208/9208), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 44060 (delta 9202), reused 9201 (delta 9201), pack-reused 34852
Receiving objects: 100% (44060/44060), 13.96 MiB | 61.00 KiB/s, done.
Resolving deltas: 100% (33758/33758), completed with 1387 local objects.
From https://github.com/Homebrew/brew
* [new branch] dependabot/bundler/Library/Homebrew/rubocop-1.8.0 -> origin/dependabot/bundler/Library/Homebrew/rubocop-1.8.0
* [new branch] dependabot/github_actions/dessant/lock-threads-486f7380c15596f92b724e4260e4981c68d6bde6 -> origin/dependabot/github_actions/dessant/lock-threads-486f7380c15596f92b724e4260e4981c68d6bde6
686760d10..8c4183abc master -> origin/master
。。。==> Resetting /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
Checking out files: 100% (5592/5592), done.
Branch 'master' set up to track remote branch 'master' from 'origin'.
Reset branch 'master'
Your branch is up to date with 'origin/master'.
SENRSL:Downloads senrsl$ brew --version
Homebrew 2.7.2-50-g8c4183a
Homebrew/homebrew-core (git revision bd7fb; last commit 2021-01-08)
SENRSL:Downloads senrsl$
然后重新卸载重装python3
卸载一直卡在网络上
SENRSL:blog senrsl$ brew uninstall --ignore-dependencies -v
python3
==> Tapping homebrew/cask
git clone https://github.com/Homebrew/homebrew-cask
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
Cloning into
'/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...
fatal: unable to access 'https://github.com/Homebrew/homebrew-cask/':
transfer closed with outstanding read data remaining
Error: Failure while executing; `git clone https://github.com/Homebrew/homebrew-cask
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask` exited
with 128.
SENRSL:blog senrsl$
1,python读取xml
分 dom,sax,elementTree三种方式
为了校验xml准确性,选择dom
#!/usr/bin/python # -*- coding: UTF-8 -*- # from xml.dom.minidom import parse import xml.dom.minidom # 使用minidom解析器打开 XML 文档 DOMTree = xml.dom.minidom.parse("res/netease.xml") # DOMTree = xml.dom.minidom.parse("res/test.xml") print DOMTree.nodeName print DOMTree.firstChild.tagName root = DOMTree.documentElement # root属性 # if root.hasAttribute("shelf"): # print "Root element : %s" % collection.getAttribute("shelf") ''' <blog> <id>1799495571</id> <userId>69731064</userId> <userName>cool.china</userName> <userNickname><![CDATA[东川々靖竹]]></userNickname> <title><![CDATA[迁]]></title> <publishTime>1470973483509</publishTime> <ispublished>1</ispublished> <classId>88735823</classId> <className><![CDATA[晓风残月]]></className> <allowView>-100</allowView> <content><![CDATA[LOFTER4D9CD38BEE8C7494AA14F3B218F5C8E3<wbr>]]></content> <valid>0</valid> <moveForm>NONE</moveForm> </blog> ''' # 生成集合 blogList = root.getElementsByTagName("blog") # 迭代集合 for blog in blogList: print "\n*****blog*****" # if movie.hasAttribute("title"): # print "Title: %s" % movie.getAttribute("title") id = blog.getElementsByTagName('id')[0].childNodes[0].data userId = blog.getElementsByTagName('userId')[0].childNodes[0].data userName = blog.getElementsByTagName('userName')[0].childNodes[0].data userNickname = blog.getElementsByTagName('userNickname')[0].childNodes[0].data title = blog.getElementsByTagName('title')[0].childNodes[0].data publishTime = blog.getElementsByTagName('publishTime')[0].childNodes[0].data ispublished = blog.getElementsByTagName('ispublished')[0].childNodes[0].data classId = blog.getElementsByTagName('classId')[0].childNodes[0].data className = blog.getElementsByTagName('id')[0].childNodes[0].data allowView = blog.getElementsByTagName('allowView')[0].childNodes[0].data content = blog.getElementsByTagName('content')[0].childNodes[0].data valid = blog.getElementsByTagName('valid')[0].childNodes[0].data moveForm = blog.getElementsByTagName('moveForm')[0].childNodes[0].data print "id: %s,\nuserId: %s,\nuserName: %s,\nuserNickname: %s,\ntitle: %s,\npublishTime: %s,\nispublished: %s,\nclassId: %s,\nclassName: %s,\nallowView: %s,\ncontent: %s,\nvalid: %s,\nmoveForm: %s" % (id,userId,userName,userNickname,title,publishTime,ispublished,classId,className,allowView,content,valid,moveForm) # format = movie.getElementsByTagName('format')[0] # print "Format: %s" % format.childNodes[0].data # rating = movie.getElementsByTagName('rating')[0] # print "Rating: %s" % rating.childNodes[0].data # description = movie.getElementsByTagName('description')[0] # print "Description: %s" % description.childNodes[0].data
用Python干活是真简单。。。。
2,xml文件修正
默认网易导出的xml有问题,找个编辑器,把格式改正确
SENRSL:blog senrsl$ python xml/dom.py
Traceback (most recent call last):
File "xml/dom.py", line 8, in <module>
DOMTree = xml.dom.minidom.parse("res/netease.xml")
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/dom/minidom.py", line 1918, in parse
return expatbuilder.parse(file)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/dom/expatbuilder.py", line 924, in parse
result = builder.parseFile(fp)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/dom/expatbuilder.py", line 207, in parseFile
parser.Parse(buffer, 0)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 6333, column 6
SENRSL:blog senrsl$
看起来是几个特殊符号或者什么的不支持,按提示行 替换,解析成功!
3,blogger生成token
现在搞这个真的是好简单了呀,直接一篇文章从头讲到尾 developers.google.com/blogger/docs/3.0/using#auth
重点就是第一个按钮,创建项目,配置回调,生成token
此处配图1
4,跑blogger sample项目
现在卡在网络上了。。。。google提供的api不支持3.6版本以下,等一开始的python3配置。。。。
几个小时一直失败,替换源试试
5,home brew替换源
看起来网络问题好多遇到的呢
1)替换默认镜像源
SENRSL:blog senrsl$ cd "$(brew --repo)"
SENRSL:Homebrew senrsl$ pwd
/usr/local/Homebrew
SENRSL:Homebrew senrsl$ git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
2)替换homebrew-core镜像源
SENRSL:Homebrew senrsl$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
SENRSL:homebrew-core senrsl$ git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
3)替换homebrew-cask镜像源
SENRSL:homebrew-core senrsl$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
-bash: cd: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask: No such file or directory
SENRSL:homebrew-core senrsl$ brew install cask
Error:
homebrew-core is a shallow clone.
To `brew update`, first run:
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
This command may take a few minutes to run due to the large size of the repository.
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!
==> Downloading https://homebrew.bintray.com/bottles/gmp-6.2.1.big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/6a44705536f25c4b9f8547d44d129ae3b3657755039966ad2b86b821e187c32c?response-content-disposition
######################################################################## 100.0%
。。。==> Downloading https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tar.xz
################## 25.1%
################################################################ 90.2%
curl: (92) HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)
Error: Failed to download resource "python@3.9"
Download failed: https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tar.xz。。。
For pkg-config to find sqlite you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/sqlite/lib/pkgconfig"
SENRSL:homebrew-core senrsl$
python download花了快俩小时,90%多,然后失败。。。。
然后设置cask源地址报目录不存在
fatal: Cannot change to '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask': No such file or directory
然后 homebrew-cask一直没反应。。。。
SENRSL:blog senrsl$ brew cask
==> Tapping homebrew/cask
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...
^C
SENRSL:blog senrsl$
看了下,是这个库从头到尾就没下成功过
墙真是令人开心啊。。。。
SENRSL:blog senrsl$ cd /usr/local/Homebrew/Library/Taps/homebrew
SENRSL:homebrew senrsl$ ls
homebrew-cask homebrew-core
SENRSL:homebrew senrsl$ cd homebrew-c
-bash: cd: homebrew-c: No such file or directory
SENRSL:homebrew senrsl$ cd homebrew-cask/
SENRSL:homebrew-cask senrsl$ git remote -v
origin https://github.com/Homebrew/homebrew-cask (fetch)
origin https://github.com/Homebrew/homebrew-cask (push)
SENRSL:homebrew-cask senrsl$ pwd
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
SENRSL:homebrew-cask senrsl$ cd ..
SENRSL:homebrew senrsl$ ls
homebrew-core
SENRSL:homebrew senrsl$ pwd
/usr/local/Homebrew/Library/Taps/homebrew
SENRSL:homebrew senrsl$ ls
homebrew-core
SENRSL:homebrew senrsl$ git clone https://mirrors.ustc.edu.cn/homebrew-cask.git
Cloning into 'homebrew-cask'...
remote: Enumerating objects: 594846, done.
remote: Total 594846 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (594846/594846), 246.24 MiB | 1.56 MiB/s, done.
Resolving deltas: 100% (424446/424446), done.
SENRSL:homebrew senrsl$ ls
homebrew-cask homebrew-core
SENRSL:homebrew senrsl$ cd homebrew-cask/
SENRSL:homebrew-cask senrsl$ git remote -v
origin https://mirrors.ustc.edu.cn/homebrew-cask.git (fetch)
origin https://mirrors.ustc.edu.cn/homebrew-cask.git (push)
SENRSL:homebrew-cask senrsl$ cd ..
SENRSL:homebrew senrsl$ cd homebrew-core/
SENRSL:homebrew-core senrsl$ git remote -v
origin https://mirrors.ustc.edu.cn/homebrew-core.git (fetch)
origin https://mirrors.ustc.edu.cn/homebrew-core.git (push)
SENRSL:homebrew-core senrsl$ cd ..
SENRSL:homebrew senrsl$
4)一步到胃
假设都下载成功,直接可以替换源
SENRSL:blog senrsl$ git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
SENRSL:blog senrsl$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
SENRSL:blog senrsl$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
然后brew update
SENRSL:blog senrsl$ brew update
Error:
homebrew-core is a shallow clone.
To `brew update`, first run:
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
This command may take a few minutes to run due to the large size of the repository.
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!
SENRSL:blog senrsl$ git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
remote: Enumerating objects: 528965, done.
remote: Counting objects: 100% (528927/528927), done.
remote: Compressing objects: 100% (191232/191232), done.
remote: Total 520298 (delta 332039), reused 514337 (delta 326218)
Receiving objects: 100% (520298/520298), 197.14 MiB | 1.31 MiB/s, done.
Resolving deltas: 100% (332039/332039), completed with 4145 local objects.
From https://mirrors.ustc.edu.cn/homebrew-core
bd7fb9f9f8..8a6807be6a master -> origin/master
SENRSL:blog senrsl$ brew update
Updated 1 tap (homebrew/core).
==> New Formulae
forge gallery-dl indicators jpeg-xl lp_solve tctl
==> Updated Formulae
libffi ✔ contentful-cli gitversion lynis pdfpc sipsak
abseil cpm glooctl lzip pdftoipe sord
angle-grinder cppad gmt macos-trash perltidy sratom
ansible cproto gmt@5 mapnik petsc sstp-client
ansible-lint deark gpgme mapserver petsc-complex stella
arangodb device-mapper gradle masscan pipemeter stone-soup
argocd diff-pdf graph-tool mat2 plantuml suil
arrayfire diffoscope gtk-mac-integration math-comp plzip tarantool
ask-cli dnsviz gtk4 mda-lv2 pnpm tclap
aws-sdk-cpp doctl haproxy meson points2grid terragrunt
awscli@1 doxygen imagemagick minio poppler terrahub
ballerina dxpy imagemagick@6 minio-mc postgis texlab
bcpp efl jupyterlab mockolo pqiv tflint
binaryen eg-examples kde-extra-cmake-modules molecule profanity tox
bingrep emscripten kde-karchive mysql++ proteinortho udunits
biosig evernote2md kde-kdoctools nats-streaming-server protoc-gen-gogo v8
bpytop evince kde-ki18n neo4j protoc-gen-gogofaster vala
bullet exploitdb kde-threadweaver newsboat pyenv vale
bup feh kubie ocrmypdf pympress verilator
bwm-ng flux libosmium opencv python@3.9 vips
byacc fq libplctag opencv@3 repo wasmer
cdk fsevent_watch libqalculate openimageio rhash webpack
ceres-solver gateway-go libusrsctp ortp rust yq
certbot gatsby-cli logrotate osmium-tool sbtenv zola
cfn-lint gdal luaradio pdal sentencepiece
checkov ghz lv2 pdf2svg server-go
closure-compiler ghz-web lxc pdfgrep simple-tiles
SENRSL:blog senrsl
检测
SENRSL:blog senrsl$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!
Warning: Suspicious https://github.com/Homebrew/brew git origin remote found.
The current git origin is:
https://mirrors.ustc.edu.cn/brew.git
With a non-standard origin, Homebrew won't update properly.
You can solve this by setting the origin remote:
git -C "/usr/local/Homebrew" remote set-url origin https://github.com/Homebrew/brew
Warning: Suspicious https://github.com/Homebrew/homebrew-core git origin remote found.
The current git origin is:
https://mirrors.ustc.edu.cn/homebrew-core.git
With a non-standard origin, Homebrew won't update properly.
You can solve this by setting the origin remote:
git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" remote set-url origin https://github.com/Homebrew/homebrew-core
Warning: The following directories do not exist:
/usr/local/Frameworks
/usr/local/sbin
You should create these directories and change their ownership to your account.
sudo mkdir -p /usr/local/Frameworks /usr/local/sbin
sudo chown -R $(whoami) /usr/local/Frameworks /usr/local/sbin
Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
python
unbound
SENRSL:blog senrsl$
5),brew cask
brew 是酿造,cask是酒桶
brew用来下载不带界面的、命令行下的工具和库;
brew cask带界面。
使用时,使用 brew cask install xxxx 格式。
6,重新安装python3
一样的问题
SENRSL:blog senrsl$ pip --version
pip 18.1 from /Library/Python/2.7/site-packages/pip (python 2.7)
SENRSL:blog senrsl$ pip2 --version
pip 18.1 from /Library/Python/2.7/site-packages/pip (python 2.7)
SENRSL:blog senrsl$ pip3 --version
-bash: /usr/local/bin/pip3: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8: bad interpreter: No such file or directory
SENRSL:blog senrsl$
终于把brew搞得能跑了,继续搞python3....
SENRSL:blog senrsl$ brew uninstall --ignore-dependencies python3
Error: No available formula or cask with the name "python3".
SENRSL:blog senrsl$ brew link python3
Error: No such keg: /usr/local/Cellar/python@3.9
SENRSL:blog senrsl$ brew uninstall python3
Error: No available formula or cask with the name "python3".
SENRSL:blog senrsl$ brew install python3
==> Downloading https://homebrew.bintray.com/bottles/gdbm-1.18.1_1.big_sur.bottle.tar.gz
Already downloaded: /Users/senrsl/Library/Caches/Homebrew/downloads/5e0e7fa2b01cc9aa80d6078f0994504ca47b49bd672a170afcd0618276cef25b--gdbm-1.18.1_1.big_sur.bottle.tar.gz。。。
==> Installing python@3.9 dependency: xz
==> Pouring xz-5.2.5.big_sur.bottle.tar.gz
🍺 /usr/local/Cellar/xz/5.2.5: 95 files, 1.4MB
==> Installing python@3.9
==> ./configure --prefix=/usr/local/Cellar/python@3.9/3.9.1_6 --enable-ipv6 --datarootdir=/usr/local/Cellar/python@3.9/3.9.1_6/share --datadir=/usr/loca
==> make
==> make install PYTHONAPPSDIR=/usr/local/Cellar/python@3.9/3.9.1_6
==> make frameworkinstallextras PYTHONAPPSDIR=/usr/local/Cellar/python@3.9/3.9.1_6/share/python@3.9
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/pip3
Target /usr/local/bin/pip3
already exists. You may want to remove it:
rm '/usr/local/bin/pip3'
To force the link and overwrite all conflicting files:
brew link --overwrite python@3.9
To list all files that would be deleted:
brew link --overwrite --dry-run python@3.9
Possible conflicting files are:
/usr/local/bin/pip3 -> /Library/Frameworks/Python.framework/Versions/3.8/bin/pip3
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
SENRSL:blog senrsl$
其中
Warning: Building python@3.9 from source:
The bottle needs the Apple Command Line Tools to be installed.
You can install them, if desired, with:
xcode-select --install
真是SB设计
配图 SB Python设计
SENRSL:blog senrsl$ brew link --overwrite --dry-run python@3.9
Would remove:
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
SENRSL:blog senrsl$
SENRSL:blog senrsl$ sudo mkdir /usr/local/Frameworks
SENRSL:blog senrsl$ sudo chown $USER /usr/local/Frameworks
SENRSL:blog senrsl$ brew link --overwrite --dry-run python@3.9
Would remove:
SENRSL:blog senrsl$ brew link --overwrite python@3.9
Linking /usr/local/Cellar/python@3.9/3.9.1_6... 5 symlinks created
SENRSL:blog senrsl$
6.1)再次到胃
SENRSL:blog senrsl$ brew uninstall --ignore-dependencies python3
Uninstalling /usr/local/Cellar/python@3.9/3.9.1_6... (8,660 files, 127.8MB)
SENRSL:blog senrsl$ brew install python3
==> Downloading https://homebrew.bintray.com/bottles/python%403.9-3.9.1_6.big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/48d123683fa125de9f02f7777683edda40e998f0e2dca492024c00bbd3f05ea2?response-content-disposition
######################################################################## 100.0%
==> Pouring python@3.9-3.9.1_6.big_sur.bottle.tar.gz
==> /usr/local/Cellar/python@3.9/3.9.1_6/bin/python3 -m ensurepip
==> /usr/local/Cellar/python@3.9/3.9.1_6/bin/pip3 install -v --global-option=--no-user-cfg --install-option=--force --install-option=--single-version-ex
==> /usr/local/Cellar/python@3.9/3.9.1_6/bin/pip3 wheel --wheel-dir=/usr/local/Cellar/python@3.9/3.9.1_6/Frameworks/Python.framework/Versions/3.9/lib/py
==> Caveats
Python has been installed as
/usr/local/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/usr/local/opt/python@3.9/libexec/bin
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.9/site-packages
See: https://docs.brew.sh/Homebrew-and-Python
==> Summary
🍺 /usr/local/Cellar/python@3.9/3.9.1_6: 3,932 files, 65.4MB
Removing: /usr/local/Cellar/python/3.7.3... (7,982 files, 112.5MB)
SENRSL:blog senrsl$ python3 --version
Python 3.8.2
SENRSL:blog senrsl$ pip3 --version
pip 20.3.3 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
SENRSL:blog senrsl$
环境终于TMD安好了。。。。
脑残设计
7,运行blogger sample
翻开google api 文档 github.com/googleapis/google-api-python-client
源码上库 github.com/senRsl/blog
安装google api 环境
SENRSL:blog senrsl$ ls
blogger doc res venv xml
SENRSL:blog senrsl$ pip3 install virtualenv
Collecting virtualenv
。。。
Installing collected packages: six, filelock, distlib, appdirs, virtualenv
Successfully installed appdirs-1.4.4 distlib-0.3.1 filelock-3.0.12 six-1.15.0 virtualenv-20.3.0
SENRSL:blog senrsl$ virtualenv venv/
created virtual environment CPython3.9.1.final.0-64 in 471ms
creator CPython3Posix(dest=/Users/senrsl/temp/blog/venv, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/Users/senrsl/Library/Application Support/virtualenv)
added seed packages: pip==20.3.1, setuptools==51.0.0, wheel==0.36.1
activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
SENRSL:blog senrsl$ source venv/bin/activate
(venv) SENRSL:blog senrsl$ venv/bin/pip install google-api-python-client
Collecting google-api-python-client
Downloading google_api_python_client-1.12.8-py2.py3-none-any.whl (61 kB)
。。。
Installing collected packages: six, pyasn1, urllib3, rsa, pyasn1-modules, protobuf, idna, chardet, certifi, cachetools, requests, pytz, httplib2, googleapis-common-protos, google-auth, uritemplate, google-auth-httplib2, google-api-core, google-api-python-client
Successfully installed cachetools-4.2.0 certifi-2020.12.5 chardet-4.0.0 google-api-core-1.24.1 google-api-python-client-1.12.8 google-auth-1.24.0 google-auth-httplib2-0.0.4 googleapis-common-protos-1.52.0 httplib2-0.18.1 idna-2.10 protobuf-3.14.0 pyasn1-0.4.8 pyasn1-modules-0.2.8 pytz-2020.5 requests-2.25.1 rsa-4.7 six-1.15.0 uritemplate-3.0.1 urllib3-1.26.2
WARNING: You are using pip version 20.3.1; however, version 20.3.3 is available.
You should consider upgrading via the '/Users/senrsl/temp/blog/venv/bin/python -m pip install --upgrade pip' command.
(venv) SENRSL:blog senrsl$
继续报错,oath2模块找不到
(venv) SENRSL:blog senrsl$ python blogger/blogger.py --logging_level=DEBUG
Traceback (most recent call last):
File "/Users/senrsl/temp/blog/blogger/blogger.py", line 40, in <module>
from oauth2client import client
ModuleNotFoundError: No module named 'oauth2client'
(venv) SENRSL:blog senrsl$ pip3 install --upgrade oauth2client
Collecting oauth2client
。。。
Installing collected packages: oauth2client
Successfully installed oauth2client-4.1.3
WARNING: You are using pip version 20.3.1; however, version 20.3.3 is available.
You should consider upgrading via the '/Users/senrsl/temp/blog/venv/bin/python -m pip install --upgrade pip' command.
(venv) SENRSL:blog senrsl$ python blogger/blogger.py
--logging_level=DEBUG
/Users/senrsl/temp/blog/venv/lib/python3.9/site-packages/oauth2client/_helpers.py:255:
UserWarning: Cannot access blogger.dat: No such file or directory
warnings.warn(_MISSING_FILE_MESSAGE.format(filename))
Your browser has been opened to visit:
https://accounts.google.com/o/oauth2/auth?client_id=84658793-2cmo0nspur3uh0918g2krrisr9sj6.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fblogger&access_type=offline&response_type=code
If your browser is on a different machine then exit and re-run
this
application with the command-line parameter
--noauth_local_webserver
调起来了网页,400
配图4,400
请求的时候还能搞离线模式
(venv) SENRSL:blog senrsl$ python blogger/blogger.py --logging_level=DEBUG --noauth_local_webserver
/Users/senrsl/temp/blog/venv/lib/python3.9/site-packages/oauth2client/_helpers.py:255: UserWarning: Cannot access blogger.dat: No such file or directory
warnings.warn(_MISSING_FILE_MESSAGE.format(filename))
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?client_id=84658793-2cmo0nspur3uh18g2krarrisr9sj6.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fblogger&access_type=offline&response_type=code
Enter verification code:
报错
错误 400: redirect_uri_mismatch
这意思是说 只能使用应用程序?不能用Web Client?
创建客户端ID时,不要选Web应用,要选其他设备,就好了
此处配图5
终于见到了熟悉的 选择账号页面。。。。。
然后生成一串字符串,回填到命令行,就可以执行了。。。。
然后就超时了。。。。
Traceback (most recent call last):
File "/Users/senrsl/temp/blog/blogger/blogger.py", line 83, in <module>
main(sys.argv)
File "/Users/senrsl/temp/blog/blogger/blogger.py", line 46, in main
service, flags = sample_tools.init(
File "/Users/senrsl/temp/blog/venv/lib/python3.9/site-packages/googleapiclient/sample_tools.py", line 98, in init
credentials = tools.run_flow(flow, storage, flags)
File "/Users/senrsl/temp/blog/venv/lib/python3.9/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Users/senrsl/temp/blog/venv/lib/python3.9/site-packages/oauth2client/tools.py", line 243, in run_flow
credential = flow.step2_exchange(code, http=http)
File "/Users/senrsl/temp/blog/venv/lib/python3.9/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Users/senrsl/temp/blog/venv/lib/python3.9/site-packages/oauth2client/client.py", line 2053, in step2_exchange
resp, content = transport.request(
File "/Users/senrsl/temp/blog/venv/lib/python3.9/site-packages/oauth2client/transport.py", line 280, in request
return http_callable(uri, method=method, body=body, headers=headers,
File "/Users/senrsl/temp/blog/venv/lib/python3.9/site-packages/httplib2/__init__.py", line 1985, in request
(response, content) = self._request(
File "/Users/senrsl/temp/blog/venv/lib/python3.9/site-packages/httplib2/__init__.py", line 1650, in _request
(response, content) = self._conn_request(
File "/Users/senrsl/temp/blog/venv/lib/python3.9/site-packages/httplib2/__init__.py", line 1557, in _conn_request
conn.connect()
File "/Users/senrsl/temp/blog/venv/lib/python3.9/site-packages/httplib2/__init__.py", line 1391, in connect
raise socket_err
File "/Users/senrsl/temp/blog/venv/lib/python3.9/site-packages/httplib2/__init__.py", line 1324, in connect
sock.connect((self.host, self.port))
TimeoutError: [Errno 60] Operation timed out
(venv) SENRSL:blog senrsl$
果然不会那么顺利,这很google。。。。
记得这个流程以前写过,找了一遭 果然。。。。
https://senrsl.blogspot.com/2016/08/blogspot04.html
全套流程。。。。
现在的问题:
如果用封装好的,需要调用google api client中方法,通过sample_tools.init() 得到返回 service.
使用service进行后续blogger后续操作。
但是init()一直超时。
或者 纯调用 api,手动塞token是跑通的,但是这种需要在网页得到token,后续blogger相关api都要自己写。。。。
哎。。。。
2021年01月11日20:49:01
昨天一直time out。。。。
然后提issue确认了下,的确是因为网络问题。。。。
然后,突然想起,可能是因为需要单独给终端挂代理。。。。
(venv) SENRSL:blog senrsl$ export http_proxy=http://127.0.0.1:1087;export https_proxy=http://127.0.0.1:1087;
(venv) SENRSL:blog senrsl$ ping google.com
PING google.com (93.46.8.90): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1。。。。
(venv) SENRSL:blog senrsl$ python ../google-api-python-client/samples/blogger/blogger.py --noauth_local_webserver
/Users/senrsl/temp/blog/venv/lib/python3.9/site-packages/oauth2client/_helpers.py:255: UserWarning: Cannot access blogger.dat: No such file or directory
warnings.warn(_MISSING_FILE_MESSAGE.format(filename))
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?client_id=xxx-xxx.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fblogger&access_type=offline&response_type=code
Enter verification code: 4/1AY0e-g7kIn-8E3L44o7u8CGY7xxx
Authentication successful.
This user's display name is: senRsl
The blog named '海底夜行人' is at: http://senrsl.blogspot.com/
The posts for 海底夜行人:
2020年底济南买房记01 从定金到一周内10% (http://senrsl.blogspot.com/2021/01/202001-10.html)
Android rtmp直播04 Android使用MediaCodec录制mp4 (http://senrsl.blogspot.com/2021/01/android-rtmp04-androidmediacodecmp4.html)
Android rtmp直播03 FFmpeg Android so的简单用法 (http://senrsl.blogspot.com/2020/12/android-rtmp03-ffmpeg-android-so.html)
。。。。啊 (http://senrsl.blogspot.com/2010/10/blog-post.html)
(venv) SENRSL:blog senrsl$
终于通了,靠。。。。。
ping不通是因为ping在网络第三层,ICMP层,
7.1)网络七层协议
网络七层协议(OSI):7 应用层 6 表示层 5 会话层 4 传输层 3 网络层 2 数据链路层 1 物理层
上层模型依赖下层模型
1,ping命令使用的ICMP协议,作用在OSI模型第3层——网络层(IP层)
2,SOCKS作用在OSI模型的第5层——会话层
3,HTTP、FTP、SMTP作用在OSI模型第7层——网络层
ss支持的代理协议是socks(5 会话层)和http(7 应用层),最终都依赖于TCP(4 传输层)和IP协议(3
网络层),发送tcp数据包,但并不能代理第3层——网络层
7.2)会自动保存.dat这样就不用每次认证
(venv) SENRSL:blog senrsl$ python blogger/blogger.py --logging_level=DEBUG --noauth_local_webserver
This user's display name is: senRsl
(venv) SENRSL:blog senrsl$
目录下多了个 blogger.dat,里面是 token信息。。。。
实际请求使用的就是 里面的access_token
8,清晰类别
原blogspot类别梳理,与netease类别合并
确定账号
9,idea 配置 python env
有个开发工具是多么的重要。。。。
拿sublime写 代码多了太难受了。。。。
给idea安装Python插件,先随便建个空python项目
然后 from oauth2client import client 会报找不到
因为环境不对,默认是主python环境,blog这个是单独的venv
File -> Project Stucture ,配置两步
1,SDK增加虚拟环境路径
此处配图8
增加虚拟环境后,可以看到idea能自己找到venv里google 相关的库
配图9
2,Project Structure这个框,Project Setting -> Project
修改Project SDK 为 刚增加的SDK。
这样项目里就能找到 venv里的库了。。。。
然后 回首 重新建个实际用的项目,发现 建项目时选择sdk就可以直接选 venv的环境。。。。
此处配图10
10,导入
同一个操作有上限啊。。。。
Traceback (most recent call last):
File "/Users/senrsl/temp/blog/blogger/blogspot163/blogger.py",
line 208, in <module>
main(sys.argv)
File "/Users/senrsl/temp/blog/blogger/blogspot163/blogger.py",
line 143, in main
insert(
File "/Users/senrsl/temp/blog/blogger/blogspot163/blogger.py",
line 181, in insert
resultDetail = posts.insert(
File
"/Users/senrsl/temp/blog/venv/lib/python3.9/site-packages/googleapiclient/_helpers.py",
line 134, in positional_wrapper
return wrapped(*args, **kwargs)
File
"/Users/senrsl/temp/blog/venv/lib/python3.9/site-packages/googleapiclient/http.py",
line 915, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when
requesting https://blogger.googleapis.com/v3/blogs/8251415504136136868/posts?alt=json
returned "We're sorry, but one or more limits for the requested
action have been exceeded.". Details: "We're sorry, but one or
more limits for the requested action have been exceeded.">
好像以前也遇到过。。。。
找了一遭,说是每天最多只能建100个帖子。。。。。
水王附体的时候,这哪够用。。。。
2021年01月12日18:13:33
senRsl
2019年05月08日18:53:56
没有评论 :
发表评论