Created
May 6, 2016 00:50
-
-
Save professorjamesmoriarty/4cc985c13c02bcd61e0570b5b10ed24a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# vim:fenc=utf-8 | |
# | |
# Copyright © 2016 Johnathan "Shaggytwodope" Jenkins <[email protected]> | |
# | |
# Distributed under terms of the GPL2 license. | |
import os | |
import urllib.request | |
import shutil | |
localaptsfile = "/home/shaggy/.calcurse/myapts" | |
aptsfile = "/home/shaggy/.calcurse/apts" | |
aptsfilebackup = "/home/shaggy/.calcurse/apts_backup" | |
aptstempfile = "/home/shaggy/.calcurse/aptstemp" | |
urls = { | |
"tv.ics": "http://followshows.com/ical/agDBZ7tj", | |
"anime.ics": | |
"http://animecalendar.net/user/ical/11986/469cc8a1f781cffe56dd993294ad83c8" | |
} | |
def main(): | |
for (name, url) in urls.items(): | |
print("downloading %s" % name) | |
try: | |
urllib.request.urlretrieve(url, name) | |
except IOError: | |
print("There was a problem downloading the data for " + name) | |
print("Clearing Old Data...") | |
try: | |
os.remove(aptsfile) | |
except: | |
pass | |
print("Importing Calendar Data...") | |
for (name, url) in urls.items(): | |
try: | |
os.system("calcurse -i " + str(name) + ">/dev/null 2>&1") | |
except OSError: | |
print("There was a problem importing the data for " + name) | |
shutil.move(aptsfile, aptstempfile) | |
filenames = [localaptsfile, aptstempfile] | |
with open(aptsfile, "w") as outfile: | |
for fname in filenames: | |
with open(fname) as infile: | |
outfile.write(infile.read()) | |
print("Backing up..") | |
shutil.copy(aptsfile, aptsfilebackup) | |
print("Cleaning up downloaded files...") | |
os.remove(aptstempfile) | |
for (name, url) in urls.items(): | |
try: | |
os.remove(name) | |
except OSError: | |
pass | |
print("DONE") | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment