Python脚本没有写入磁盘

时间:2014-01-17 09:21:20

标签: python file-io

我正在尝试编写一个小脚本,它从rss-feedreader中抓取链接并将它们写入文本文件。

奇怪的是它昨天正常工作,当我通过点击它或在控制台中启动它时仍在工作,但不是从rss-reader启动时。

即使从rss-reader启动它也基本上工作,但它不会写入文件,虽然我收到“成功通知”并且没有错误!

#!/usr/bin/python
import sys  # getting the passed arguments
import time
from gi.repository import Notify  # display a notification
import datetime

# generating the file name
year = str(datetime.date.today().isocalendar()[0])
week = str(datetime.date.today().isocalendar()[1])

# adds a leading zero if week is < 10
if len(week) < 2:
    week = '0' + week

grabbed = 'news_' + year + '_kw_' + week

try:
    url = sys.argv[1] + '\n'
    # success notification
    topic = 'Grabbed and written to KW ' + week
except IndexError:
    url = 'Error: ' + 'No link received! ' + time.strftime("%Y.%m.%d - %H:%M:%S") + '\n'
    # display a error notification
    topic = "Grabbing failed :("

try:
    file = open("test.txt", "a")
    file.write(url)
    file.close()
except IOError:
    topic = 'Error:'
    url = 'File was not written!'

# display the notification
Notify.init("Notification")
Hello = Notify.Notification.new(topic, url, "dialog-information")
Hello.show()

我尝试了不同的RSS阅读器,正如我所说它昨天工作但现在不再工作了。

(我正在运行Linux)

我从rss-reader启动它,将“使用外部浏览器打开”字段更改为“/path/to/my/script/grabber.py%u”因此,每次点击链接都会启动它。

0 个答案:

没有答案