一个python库,用于将web资源推送到公共web档案中
archivenow的Python项目详细描述
将Web资源推入Web存档的工具
立即存档(archive now)当前配置为将资源推入六个公共web存档。通过编写一个新的归档处理程序(例如myarchive_handler.py)并将其放在文件夹“handlers”中,您可以轻松地添加更多的归档文件。
如下文所述,此库可通过以下方式使用:
- 命令行界面(cli)
- Web服务
- 码头集装箱
- Python
安装
最新版本的archivenow可以使用pip安装:
$ pip install archivenow
包含尚未发布的更改的最新开发版本可以从源安装:
$ git clone git@github.com:oduwsdl/archivenow.git
$ cd archivenow
$ pip install -r requirements.txt
$ pip install ./
cli用法
通过提供-h或-help标志,可以访问archivenow中的子命令用法,如下所示。
$ archivenow -h usage: archivenow.py [-h][--mg][--wc][--cc][--cc_api_key [CC_API_KEY]][--is][--st][--ia][--warc [WARC]][-v][--all][--server][--host [HOST]][--agent [AGENT]][--port [PORT]][URI] positional arguments: URI URI of a web resource optional arguments: -h, --help show this help message and exit --mg Use Megalodon.jp --wc Use The WebCite Archive --cc Use The Perma.cc Archive --cc_api_key [CC_API_KEY] An API KEY is required by The Perma.cc Archive --is Use The Archive.is --st Use The Archive.st --ia Use The Internet Archive --warc [WARC] Generate WARC file -v, --version Report the version of archivenow --all Use all possible archives --server Run archiveNow as a Web Service --host [HOST] A server address --agent [AGENT] Use "wget" or "squidwarc"for WARC generation --port [PORT] A port number to run a Web Service
示例
例1
将网页(www.foxnews.com)保存在Internet存档中:
$ archivenow --ia www.foxnews.com https://web.archive.org/web/20170209135625/http://www.foxnews.com
例2
默认情况下,如果未提供可选参数,则网页(例如www.foxnews.com)将保存在Internet存档中:
$ archivenow www.foxnews.com https://web.archive.org/web/20170215164835/http://www.foxnews.com
例3
要将网页(www.foxnews.com)保存在Internet存档(archive.org)和存档中,请执行以下操作:
$ archivenow --ia --is www.foxnews.com https://web.archive.org/web/20170209140345/http://www.foxnews.com http://archive.is/fPVyc
例4
将网页(https://nypost.com/)保存在所有配置的Web存档中。除了在所有配置的存档文件中保留页面外,此命令还将在本地创建一个warc文件:
$ archivenow --all https://nypost.com/ --cc_api_key $Your-Perma-CC-API-Key
http://archive.is/dcnan
https://perma.cc/53CC-5ST8
https://web.archive.org/web/20181002081445/https://nypost.com/
https://megalodon.jp/2018-1002-1714-24/https://nypost.com:443/
http://www.webcitation.org/72ramyxT2
https://Archive.st/archive/2018/10/nypost.com/h5m1/nypost.com/index.html
https_nypost.com__96ec2300.warc
例5
下载网页(https://nypost.com/)并创建warc文件:
$ archivenow --warc=mypage --agent=wget https://nypost.com/ mypage.warc
服务器
您可以作为web服务运行archivenow。您可以指定服务器地址和/或端口号(例如,-主机本地主机-端口12345)
$ archivenow --server Running on http://0.0.0.0:12345/ (Press CTRL+C to quit)
例6
要通过Web服务将网页(www.foxnews.com)保存在Internet存档中,请执行以下操作:
$ curl -i http://0.0.0.0:12345/ia/www.foxnews.com HTTP/1.0 200 OK Content-Type: application/json Content-Length: 95 Server: Werkzeug/0.11.15 Python/2.7.10 Date: Tue, 02 Oct 201808:20:18 GMT {"results": ["https://web.archive.org/web/20181002082007/http://www.foxnews.com"]}
例7
通过Web服务将网页(www.foxnews.com)保存在所有配置的存档中:
$ curl -i http://0.0.0.0:12345/all/www.foxnews.com HTTP/1.0 200 OK Content-Type: application/json Content-Length: 385 Server: Werkzeug/0.11.15 Python/2.7.10 Date: Tue, 02 Oct 201808:23:53 GMT {"results": ["Error (The Perma.cc Archive): An API Key is required ", "http://archive.is/ukads", "https://web.archive.org/web/20181002082007/http://www.foxnews.com", "http://Archive.st/ikxq", "Error (Megalodon.jp): We can not obtain this page because the time limit has been reached or for technical ... ", "http://www.webcitation.org/72rbKsX8B"]}
例8
因为perma.cc需要一个api密钥,所以http请求应该如下:
$ curl -i http://127.0.0.1:12345/all/https://nypost.com/?cc_api_key=$Your-Perma-CC-API-Key
或仅使用perma.cc:
$ curl -i http://127.0.0.1:12345/cc/https://nypost.com/?cc_api_key=$Your-Perma-CC-API-Key
作为Docker容器运行
$ docker image pull oduwsdl/archivenow
运行archivenow的不同方式
$ docker container run -it --rm oduwsdl/archivenow -h
可在127.0.0.1:12345访问:
$ docker container run -p 12345:12345 -it --rm oduwsdl/archivenow --server --host 0.0.0.0
127.0.0.1:22222:
$ docker container run -p 22222:11111 -it --rm oduwsdl/archivenow --server --port 11111 --host 0.0.0.0
将网页(http://www.cnn.com)保存在Internet存档中
$ docker container run -it --rm oduwsdl/archivenow --ia http://www.cnn.com
python用法
>>> from archivenow import archivenow
例9
将网页(www.foxnews.com)保存在网站存档中:
>>> archivenow.push("www.foxnews.com","wc")['http://www.webcitation.org/6o9LTiDz3']
例10
将网页(www.foxnews.com)保存在所有配置的存档中:
>>> archivenow.push("www.foxnews.com","all")['https://web.archive.org/web/20170209145930/http://www.foxnews.com','http://archive.is/oAjuM','http://www.webcitation.org/6o9LcQoVV','Error (The Perma.cc Archive): An API KEY is required]
例11
在perma.cc中保存网页(www.foxnews.com):
>>> archivenow.push("www.foxnews.com","cc",{"cc_api_key":"$YOUR-Perma-cc-API-KEY"})['https://perma.cc/8YYC-C7RM']
例12
要从python启动服务器,请执行以下操作。可以传递服务器/端口号(例如,start(port=1111,host='localhost')):
>>> archivenow.start()2017-02-09 15:02:37 Running on http://127.0.0.1:12345 (Press CTRL+C to quit)
可以通过在“handlers”目录中创建处理程序文件来添加其他存档。
例如,如果我想添加一个名为“My Archive”的新存档,我将创建一个文件“ma_handler.py”,并将其存储在文件夹“handlers”中。“ma”将是存档标识符,因此要通过python代码将网页(如www.cnn.com)推送到这个存档,我应该写:
archivenow.push("www.cnn.com","ma")
在文件“ma_handler.py”中,类的名称必须是“ma_handler”。这个班必须至少有一个名为“push”的函数,有一个参数。有关如何组织新配置的存档处理程序的示例,请参阅现有的handler files。
可以通过以下选项之一删除存档:
- 从文件夹“handlers”中删除存档处理程序文件
- 将存档处理程序文件重命名为不以“_handler.py”结尾的其他名称
- 在处理程序文件中将变量“enabled”设置为“false”
注释
Internet存档(IA)将创建“相同”资源的不同副本之间的时间间隔设置为至少两分钟。
例如,如果您在晚上10:00向ia发送捕获请求(www.cnn.com),ia将创建此uri的新副本(c)。然后,ia将返回c以获取在晚上10:02之前收到的对此uri的存档的所有请求。对archive.is使用相同的提交过程需要5分钟的时间间隔。