Input now downloads file from github

This commit is contained in:
Roland Meertens
2017-12-18 16:58:30 +01:00
parent f594f375de
commit 2ddbe37764

View File

@@ -38,6 +38,9 @@
"%matplotlib inline\n", "%matplotlib inline\n",
"import matplotlib.pyplot as plt\n", "import matplotlib.pyplot as plt\n",
"\n", "\n",
"import os\n",
"import urllib.request\n",
"\n",
"import re\n", "import re\n",
"import numpy as np\n", "import numpy as np\n",
"import math\n", "import math\n",
@@ -65,7 +68,16 @@
"\n", "\n",
"def Input(day, year=2017):\n", "def Input(day, year=2017):\n",
" \"Open this day's input file.\"\n", " \"Open this day's input file.\"\n",
" return open('data/advent{}/input{}.txt'.format(year, day))\n", " directory = 'advent{}/'.format(year)\n",
" filename = directory+'input{}.txt'.format(day)\n",
" try:\n",
" return open(filename)\n",
" except FileNotFoundError:\n",
" if not os.path.exists(directory):\n",
" os.makedirs(directory)\n",
"\n",
" urllib.request.urlretrieve(\"https://raw.githubusercontent.com/norvig/pytudes/master/data/\" + filename, filename)\n",
" return Input(day)\n",
" \n", " \n",
"def array(lines):\n", "def array(lines):\n",
" \"Parse an iterable of str lines into a 2-D array. If `lines` is a str, splitlines.\"\n", " \"Parse an iterable of str lines into a 2-D array. If `lines` is a str, splitlines.\"\n",