如何从软件包中提取版本
我正在尝试从基于 this 堆栈溢出帖子。具体来说,我正在使用 repares api “ best_release.json”呼叫。我有以下示例:
- 7-zip: https:/ best_release.json
- keepass: https://sourceforge.net/projects/projects/proexts/prosass/pearsass/keepass/kesket_release.jrelease.json.json.json.json
- OpenOffeoffice..orgice.org: https:///sourceforge.net/prodectss/prodignt/prodignts/prodignts/openofficeorgeorg.mirror/best_mirror/best_mirrore.a a a a a >
使用以下代码段:
import requests
"""
Un/comment the following lines to change the project name and test
different responses.
"""
proj = "keepass"
# proj = "sevenzip"
# proj = "openofficeorg.mirror"
r = requests.get(f'https://sourceforge.net/projects/{proj}/best_release.json')
json_resp = r.json()
print(json_resp['release']['filename'])
i接收每个软件包的相应结果:
- 7-zip:
/7-zip/22.00/7Z2200-linux-x86.tar.xz
- keepass:
/keep/keepass 2.x/2.51.1/2.51/2.51/2.51/ keepass-2.51.1.zip
- openoffice.org:
/extdended/iso/en/oo_3.3.0_win_x86_install_en-us_20110219.iso
我想知道如何从这些不同的软件包中提取文件版本。查看结果,可以看到有不同的命名约定。例如,7 ZIP将文件版本以“ 22.00”的速度在第二个目录级别中。但是,Keepass将其置于第二个目录级别以及文件名本身。 OpenOffice.org将其放入文件名中。
有没有办法进行某种模糊匹配,可以尝试提取给定文件名的“最佳猜测”文件版本?
我想到使用正则表达式,
。例如,我可以使用(re
re\ d+
)捕获组来捕获一个或多个数字,如在这里。但是,这也将捕获我不想要的“ x86”之类的文本。我只是想要一些看上去最接近版本编号的文本,但是我不确定该怎么做。
I'm trying to extract the version number from software packages hosted on SourceForge based on this Stack Overflow post. Specifically, I'm using the Release API and the "best_release.json" call. I have the following examples:
- 7-zip: https://sourceforge.net/projects/sevenzip/best_release.json
- KeePass: https://sourceforge.net/projects/keepass/best_release.json
- OpenOffice.org:
https://sourceforge.net/projects/openofficeorg.mirror/best_release.json
Using the following code snippet:
import requests
"""
Un/comment the following lines to change the project name and test
different responses.
"""
proj = "keepass"
# proj = "sevenzip"
# proj = "openofficeorg.mirror"
r = requests.get(f'https://sourceforge.net/projects/{proj}/best_release.json')
json_resp = r.json()
print(json_resp['release']['filename'])
I receive the respective results for each package:
- 7-Zip:
/7-Zip/22.00/7z2200-linux-x86.tar.xz
- KeePass:
/KeePass 2.x/2.51.1/KeePass-2.51.1.zip
- Openoffice.org:
/extended/iso/en/OOo_3.3.0_Win_x86_install_en-US_20110219.iso
I'm wondering how I can extract the file versions from these disparate packages. Looking at the results, one can see that there are different naming conventions. For example, 7-Zip puts the file version as "22.00" in the second directory level. KeePass, however, puts it in the second directory level as well as the filename itself. OpenOffice.org puts it inside the filename.
Is there a way to do some sort of fuzzy match that can attempt to extract a "best guess" file version given a filename?
I thought of using regular expressions, re
. For example, I can use the (\d+
) capture group to capture one or more digits, as demonstrated here. However, this would also capture text such as "x86," which I don't want. I just desire some text that looks closest to a version number, but I'm unsure how to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论