Repository: aau-network-security/richkit

Issue:
Fix example from README.md: retrieve.symantec.LocalCategoryDB
```
$ ipython
Python 3.7.0 (default, Feb  4 2020, 14:16:38) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.12.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: >>> from richkit.retrieve.symantec import fetch_from_internet 
   ...: >>> from richkit.retrieve.symantec import LocalCategoryDB 
   ...: >>> 
   ...: >>> urls = ["www.aau.dk","www.github.com","www.google.com"] 
   ...: >>> 
   ...: >>> local_db = LocalCategoryDB() 
   ...: >>> for url in urls: 
   ...: ...     url_category=local_db.get_category(url) 
   ...: ...     if url_category=='': 
   ...: ...         url_category=fetch_from_internet(url) 
   ...: ...     print(url_category) 
   ...:                                                                                                               
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-1-4c50769c2b82> in <module>
      4 urls = ["www.aau.dk","www.github.com","www.google.com"]
      5 
----> 6 local_db = LocalCategoryDB()
      7 for url in urls:
      8     url_category=local_db.get_category(url)

~/git-reps/richkit/richkit/retrieve/symantec.py in __init__(self)
     49     def __init__(self):
     50 
---> 51         self.url_to_category = read_categorized_file()
     52 
     53     def get_category(self, url):

~/git-reps/richkit/richkit/retrieve/symantec.py in read_categorized_file()
    149     url_to_category = dict()
    150     if not os.path.exists(categorized_urls_file):
--> 151         open(categorized_urls_file,'w').close()
    152     else:
    153         with open(categorized_urls_file, "r") as ins:

FileNotFoundError: [Errno 2] No such file or directory: 'dat/retrieve/data/categorized_urls.txt'

```

Discussion:

Patch:
diff --git a/.gitignore b/.gitignore
index 65f3e29..dc169e2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -109,4 +109,7 @@ venv.bak/
 
 # mypy
 .mypy_cache/
-.idea/*
\ No newline at end of file
+.idea/*
+
+# caches for of resources fetched from Internet, used in richkit
+richkit/retrieve/data/categorized_urls.txt
\ No newline at end of file
diff --git a/richkit/retrieve/symantec.py b/richkit/retrieve/symantec.py
index 25dc859..4860980 100644
--- a/richkit/retrieve/symantec.py
+++ b/richkit/retrieve/symantec.py
@@ -2,7 +2,7 @@
 
 This is generated to get categories of given urls, normally it fetches
 category from symantec web service then saves it to local file which
-is called `categorized_urls` under `dat/retrieve/data/`
+is called `categorized_urls` under `richkit/retrieve/data/`
 
 
 How to use:
@@ -38,9 +38,9 @@ Configuration
 Get one here: http://www1.k9webprotection.com/get-k9-web-protection-free
 """
 categories_url = "https://gitlab.com/snippets/1740321/raw"
-data_path = Path("dat/retrieve/data/")
-categories_file_path=data_path / "categories_list.txt"
-categorized_urls_file =data_path / "categorized_urls.txt"
+data_path = Path("richkit/retrieve/data/")
+categories_file_path = data_path / "categories_list.txt"
+categorized_urls_file = data_path / "categorized_urls.txt"
 
 k9License = 'Replace_by_your_own_license'
 


Test patch:
diff --git a/richkit/test/retrieve/test_symantec.py b/richkit/test/retrieve/test_symantec.py
index 9cec52a..d53abba 100644
--- a/richkit/test/retrieve/test_symantec.py
+++ b/richkit/test/retrieve/test_symantec.py
@@ -1,3 +1,4 @@
+from richkit.retrieve.symantec import read_categorized_file
 from richkit.retrieve.symantec import fetch_from_internet
 from richkit.retrieve.symantec import fetch_categories
 from richkit.retrieve.symantec import load_categories
@@ -7,9 +8,11 @@ import unittest
 
 import os.path
 
-
 class SymantecTestCase(unittest.TestCase):
 
+    def test_read_categorized_file(self):
+        self.assertIsInstance(read_categorized_file(), dict)
+
     def test_fetch_categories(self, file_path='categories_list.txt'):
         # make sure that categories url is accessible and fetched correctly
         categories = fetch_categories(categories_url, file_path)