如何用python编写这个bash脚本

2024-10-02 12:31:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个

 curl -s http://mcupdate.tumblr.com/rss | egrep -o -e 'le>Minecraft [0-9]\.[0-9]\.[0-9]|le>Minecraft [0-9]\.[0-9]' | head -1 | egrep -o -e '[0-9]\.[0-9]\.[0-9]|[0-9]\.[0-9]'

我需要用python写这个,我试过了,但不知道怎么做

它是一个开源的python minecraft启动程序


Tags: 程序lecomhttptumblr开源curlhead
2条回答

此代码段将执行以下几个简单步骤:

1)从此站点检索RSS源mcupdate.tumblr.com 2) 查找“Minecraft”的RegExp,它比“\”多一个数字,比“than one digit than”多一个数字。或者只是minecraft和2(“\”+数字)。 3) 而不是只选择最后一个结果(推荐) 4) 再次寻找那些数字(这次没有雷击机)。你知道吗

如果您只使用第一个命令(最多使用第一个“|”),并查看下载的文件以获得实际解析内容的“感觉”,那就更好了。你知道吗

所有这些都应该可以通过标准的Python库来实现。你知道吗

尝试查看urllib2文档来获取RSS提要。您还可以查看RSS libraries来解析它。你不需要使用grep,你需要一个版本号。你知道吗

import feedparser
feed = feedparser.parse('http://mcupdate.tumblr.com/rss')
item_titles = [item['title'] for item in feed['items']] # get the items titles
minecraft_versions = [title for title in item_titles if re.match('^Minecraft [0-9\.]+$',title)] # keep the titles that matches the regex
latest_version = minecraft_versions[0][10:] # get the latest version

相关问题 更多 >

    热门问题