Преглед изворни кода

search author on wikipedia

Tobias Simetsreiter пре 4 година
родитељ
комит
25f0ab5774
3 измењених фајлова са 22 додато и 12 уклоњено
  1. 4 4
      Makefile
  2. 1 1
      simpilib/__init__.py
  3. 17 7
      simpilib/eink.py

+ 4 - 4
Makefile

@@ -9,11 +9,11 @@ run:
 rerun: update run
 
 deploy: bcmlib wiringpi pythonlib
+	-ln -s sub/wavesharelib/RaspberryPi&JetsonNano/python/ wavesharelib
 
 update:
-	ssh ${RASPI_REMOTE} mkdir -p ${DEPLOY_DIR}/sub/
-	rsync -ai Makefile config.mk simpilib bin ${RASPI_REMOTE}:${DEPLOY_DIR}/
-	rsync -ai --delete sub/wavesharelib/RaspberryPi\&JetsonNano/python/ ${RASPI_REMOTE}:${DEPLOY_DIR}/wavesharelib/
+	ssh ${RASPI_REMOTE} mkdir -p ${DEPLOY_DIR}
+	rsync -ai --delete ./ ${RASPI_REMOTE}:${DEPLOY_DIR}/
 
 install_ssh: update remote/deploy
 
@@ -21,7 +21,7 @@ ssh/%:
 	ssh ${RASPI_REMOTE} "cd raspi-zero-waveshare;./bin/simpi.py ${*}"
 
 remote/%:
-	ssh ${RASPI_REMOTE} "cd raspi-zero-waveshare;$(MAKE) ${*}"
+	ssh ${RASPI_REMOTE} "cd ${DEPLOY_DIR};$(MAKE) ${*}"
 
 bcmlib:
 	wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.60.tar.gz

+ 1 - 1
simpilib/__init__.py

@@ -28,7 +28,7 @@ def loadFontSize(text, imagesize, fontpath):
     return font
 
 
-def wrapText(text, aspect_ratio, font_factor=3):
+def wrapText(text, aspect_ratio, font_factor=3.2):
     import textwrap
     text = " ".join(text.split())
     iter_width = len(text)

+ 17 - 7
simpilib/eink.py

@@ -32,9 +32,8 @@ def eink_quote_qr(args):
     # args.text = q["data"]["title"]
     # eink_text(args)
     text = q["data"]["title"]
-    url = simpilib.short_url(q["data"]["url"])
 
-    smalltext = None
+    author = None
     import re
     dashes = r"(.*)[\u002D\u058A\u05BE\u1400\u1806\u2010-\u2015\u2E17\u2E1A\u2E3A\u2E3B\u2E40\u301C\u3030\u30A0\uFE31\uFE32\uFE58\uFE63\uFF0D](.*)"
     matches = re.match(dashes, text)
@@ -42,20 +41,31 @@ def eink_quote_qr(args):
         groups = matches.groups()
         if len(groups[1]) < 30:
             text = groups[0]
-            smalltext = groups[1]
+            author = groups[1]
 
-    if not smalltext:
+    if not author:
         qt = r"(.*)\"(.*)\"(.*)"
         matches = re.match(qt, text)
         if matches:
             groups = matches.groups()
             if len(groups[0]) < 10 and len(groups[1]) > 10:
                 text = groups[1]
-                smalltext = groups[2].strip()
+                author = groups[2]
+
+    if author:
+        author = re.sub(r"[^a-zA-Z0-9 ]","", author).strip()
+        from urllib.parse import urlencode
+        args = urlencode({
+            "search": author,
+            "title": "Special:Search",
+        })
+        url = simpilib.short_url("https://wikipedia.org/w/index.php?" + args)
+    else:
+        url = simpilib.short_url(q["data"]["url"])
 
     print(text)
-    print(smalltext)
-    eink_text_qr(text, url, smalltext)
+    print(author)
+    eink_text_qr(text, url, author)
 
 def eink_text_qr(text, qrdata, smalltext=None):
     import simpilib