Browse Source

Update script to push to Known

Phyks (Lucas Verney) 4 years ago
parent
commit
1f463ba327
2 changed files with 14 additions and 3 deletions
  1. 1
    1
      blog/rss.xml
  2. 13
    2
      known.py

+ 1
- 1
blog/rss.xml View File

@@ -7,7 +7,7 @@
7 7
 		<language>fr</language>
8 8
 		<copyright>CC BY</copyright>
9 9
 		<webMaster>webmaster@phyks.me (Phyks)</webMaster>
10
-		<lastBuildDate>Fri, 02 Jan 2015 16:35:28 -0000</lastBuildDate>
10
+		<lastBuildDate>Fri, 02 Jan 2015 16:39:13 -0000</lastBuildDate>
11 11
 		<item>
12 12
 			<title>Gestion d'articles scientifiques avec BMC</title>
13 13
 			<link>http://phyks.me/2015/01/bmc.html</link>

script.py → known.py View File

@@ -6,6 +6,7 @@ import base64
6 6
 import hashlib
7 7
 import hmac
8 8
 import requests
9
+import sys
9 10
 
10 11
 """
11 12
 Script to import all the articles from this blog in Known.
@@ -38,8 +39,18 @@ def known_api(username, api_key, type, payload):
38 39
                          data=payload,
39 40
                          headers=headers)
40 41
 
42
+if len(sys.arg) < 3:
43
+    print("Usage: "+sys.argv[0]+" USERNAME API_KEY [file]")
44
+    sys.exit()
41 45
 
42
-for file in list_directory("2013") + list_directory("2014"):
46
+API_USERNAME = sys.argv[1]
47
+API_KEY = sys.argv[2]
48
+if len(sys.argv) <=3:
49
+    files = [list_directory(i) for i in ["2013", "2014", "2015"]]
50
+else:
51
+    files = [sys.argv[3]]
52
+
53
+for file in files:
43 54
     print("Processing file "+file)
44 55
     with open(file, 'r') as fh:
45 56
         soup = BeautifulSoup(fh.read())
@@ -73,4 +84,4 @@ for file in list_directory("2013") + list_directory("2014"):
73 84
     payload = {"body": content,
74 85
                "title": meta["title"],
75 86
                "created": meta["date"]}
76
-    known_api("phyks", API_KEY, "entry", payload)
87
+    known_api(API_USERNAME, API_KEY, "entry", payload)