Jared 2 anni fa
parent
commit
ab69d47dc9

+ 200 - 0
alone_redis_set.py

@@ -0,0 +1,200 @@
+import opengraph
+import redis
+
+from jinja2 import Environment, BaseLoader
+import traceback
+
+bubble3="""
+{
+  "type": "bubble",
+  "direction": "ltr",
+  "header": {
+    "type": "box",
+    "layout": "vertical",
+    "contents": [
+      {
+        "type": "box",
+        "layout": "horizontal",
+        "action": {
+          "type": "uri",
+          "uri": "https://page.line.me/choozmo"
+        },
+        "width": "100%",
+        "contents": [
+          {
+            "type": "text",
+            "text": "今日熱搜",
+            "align": "start",
+            "contents": []
+          },
+          {
+            "type": "image",
+            "url": "https://i.imgur.com/wQbJeGc.png",
+            "align": "end",
+            "aspectRatio": "4:1",
+            "aspectMode": "cover"
+          }
+        ]
+      }
+    ]
+  },
+  "body": {
+    "type": "box",
+    "layout": "vertical",
+    "paddingAll": "0px",
+    "width": "100%",
+    "backgroundColor": "#000000FF",
+    "action": {
+          "type": "uri",
+          "uri": "{{ qlink }}"
+    },
+
+    "contents": [
+      {
+        "type": "box",
+        "layout": "vertical",
+
+        "contents": [
+          {
+            "type": "image",
+            "url": "{{ imgurl }}",
+            "size": "full",
+            "aspectMode": "cover"
+          },
+          {
+            "type": "box",
+            "layout": "vertical",
+            "position": "absolute",
+            "offsetBottom": "0px",
+            "width": "100%",
+            "height": "90px",
+            "backgroundColor": "#9C8E7ECC",
+            "contents": [
+              {
+                "type": "text",
+                "text": "{{ imgtitle }}",
+                "color": "#FFFFFFFF",
+                "align": "start",
+                "wrap": true,
+                "contents": []
+              }
+            ]
+          }
+        ]
+      },
+      {
+        "type": "box",
+        "layout": "horizontal",
+        "position": "absolute",
+        "offsetTop": "10px",
+        "offsetStart": "5px",
+        "width": "100px",
+        "borderWidth": "1px",
+        "backgroundColor": "#898CDFFF",
+        "cornerRadius": "5px",
+        "contents": [
+          {
+            "type": "text",
+            "text": "{{title}}",
+            "color": "#FFFFFFFF",
+            "align": "center",
+            "contents": []
+          }
+        ]
+      }
+    ]
+  },
+"footer": {
+    "type": "box",
+    "layout": "vertical",
+    "contents": [
+      {
+        "type": "text",
+        "text": "相關關鍵字",
+        "contents": []
+      },
+      {
+        "type": "separator"
+      },
+      {
+        "type": "box",
+        "layout": "horizontal",
+        "contents": [
+          {
+            "type": "text",
+            "text": "{{K1}}",
+            "contents": []
+          },
+          {
+            "type": "text",
+            "text": "{{K2}}",
+            "contents": []
+          }
+        ]
+      },
+      {
+        "type": "box",
+        "layout": "horizontal",
+        "contents": [
+          {
+            "type": "text",
+            "text": "{{K3}}",
+            "contents": []
+          },
+          {
+            "type": "text",
+            "text": "{{K4}}",
+            "contents": []
+          }
+        ]
+      }
+    ]
+  }
+}
+"""
+
+
+data3_begin="""
+{
+  "type": "carousel",
+  "contents": [
+"""
+
+
+data3_end="""
+  ]
+}
+"""
+
+
+import dataset
+import json
+import sys
+
+
+
+result.append({'title':title,'imgurl':imgurl,'qlink':qlink,'imgtitle':imgtitle,'K1':k1,'K2':k2,'K3':k3,'K4':k4})
+
+
+r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
+
+rtemplate = Environment(loader=BaseLoader).from_string(bubble3)
+
+result=""
+for r2 in result_lst:
+#  r3 = rtemplate.render({'title':title,'imgurl':imgurl,'qlink':qlink,'imgtitle':imgtitle,'K1':k1,'K2':k2,'K3':k3,'K4':k4})
+  r3 = rtemplate.render(r2)
+
+  result+=r3
+  result+=','
+
+result=result[:-1]
+final_result=data3_begin+result+data3_end
+full_result='{"title":"今日熱搜關鍵字","data":'+final_result+'}'
+#final_result=data3_begin+result+data3_end
+
+#print(final_result)
+#r.set('btn_data',final_result)
+r.set('btn_data',full_result)
+#r.set('btn_data',data2)
+sys.exit()

BIN
liff3/icon/badge.png


BIN
liff3/icon/example.png


BIN
liff3/icon/icon.ico


BIN
liff3/icon/liff.png


+ 164 - 0
liff3/index.html

@@ -0,0 +1,164 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset="utf-8" />
+    <meta name="viewport" content="width=device-width, initial-scale=1" />
+    <title>ChoozMo LINE傳單</title>
+    <link rel="shortcut icon" href="icon/icon.ico" type="image/x-icon" />
+    <link rel="icon" href="icon/icon.ico" type="image/x-icon" />
+    <style media="screen">
+      body {
+        background: #eceff1;
+        color: rgba(0, 0, 0, 0.87);
+        font-family: Roboto, Helvetica, Arial, sans-serif;
+        margin: 0;
+        padding: 0;
+      }
+      #message {
+        background: white;
+        max-width: 1000px;
+        margin: 10px auto 16px;
+        padding: 32px 24px;
+        border-radius: 10px;
+      }
+      #message h2 {
+        color: #ffa100;
+        font-weight: bold;
+        font-size: 30px;
+        margin: 0 0 8px;
+      }
+      #message h1 {
+        font-size: 22px;
+        font-weight: 300;
+        color: rgba(0, 0, 0, 0.6);
+        margin: 0 0 16px;
+      }
+      #message p {
+        line-height: 140%;
+        margin: 16px 0 24px;
+        font-size: 14px;
+      }
+      #message a {
+        display: block;
+        text-align: center;
+        background: #039be5;
+        text-transform: uppercase;
+        text-decoration: none;
+        color: white;
+        padding: 16px;
+        border-radius: 4px;
+      }
+      #message,
+      #message a {
+        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
+      }
+      #load {
+        color: rgba(0, 0, 0, 0.4);
+        text-align: center;
+        font-size: 13px;
+      }
+      @media (max-width: 600px) {
+        body,
+        #message {
+          margin-top: 0;
+          background: white;
+          box-shadow: none;
+        }
+        body {
+          border-top: 16px solid #ffa100;
+        }
+      }
+      table {
+        margin-top: 10px;
+        border: 2px solid black;
+        border-collapse: collapse;
+        width: 100%;
+      }
+
+      table td {
+        border: 1px solid black;
+      }
+
+      table td.shrink {
+        white-space: wrap;
+        font-size: 19px;
+        padding: 5px;
+        background-color: yellow;
+      }
+      table td.shrink_context {
+        white-space: wrap;
+        font-size: 19px;
+        padding: 5px;
+        background-color: rgb(0, 255, 106);
+      }
+      table td.shrink_top {
+        white-space: nowrap;
+        background-color: black;
+        color: white;
+        font-size: 25px;
+      }
+      table td.expand {
+        width: 99%;
+        white-space: wrap;
+        font-size: 19px;
+        padding: 5px;
+      }
+      table td.expand_top {
+        width: 99%;
+        white-space: wrap;
+        background-color: black;
+      }
+      tr:hover {
+        background-color: gray;
+      }
+
+      button {
+        background-color: #4caf50; /* Green */
+        border: none;
+        color: white;
+        padding: 10px 10px;
+        text-align: center;
+        text-decoration: none;
+        display: inline-block;
+        font-size: 16px;
+        border-radius: 5px;
+        -webkit-transition-duration: 0.4s; /* Safari */
+        transition-duration: 0.4s;
+        cursor: pointer;
+      }
+
+      button:hover {
+        background-color: honeydew;
+        color: black;
+      }
+    </style>
+  </head>
+  <body>
+    <div id="message">
+      <center><h2>ChoozMo LINE傳單</h2></center>
+
+      <center>
+        <img
+          src="https://firebasestorage.googleapis.com/v0/b/uce-bot.appspot.com/o/user.jpg?alt=media&token=554b90c5-562c-469a-bfee-f36b5e3f54c9"
+          style="border-radius: 10px;"
+          width="150px"
+          height="150px"
+          id="profileImage"
+        />
+      </center>
+      <center>
+        <button onclick="login()">登入LINE</button>
+        <button onclick="logout()">登出LINE</button>
+        <button id="senddm" onclick="shareTargetPicker()">發傳單給最多五個好友</button>
+      </center>
+
+    </div>
+
+    <p id="load">ChoozMo</p>
+    <script src="https://static.line-scdn.net/liff/edge/2.1/sdk.js"></script>
+    <script src="js/liff-init.js?1234"></script>
+    <script src="js/liff-functions.js?12345"></script>
+    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
+
+  </body>
+</html>

+ 104 - 0
liff3/js/liff-functions.js

@@ -0,0 +1,104 @@
+function getProfile() {
+  liff
+    .getProfile()
+    .then(profile => {
+      console.log(JSON.stringify(profile));
+      window.alert(JSON.stringify(profile));
+    })
+    .catch(e => {
+      console.log(e);
+      window.alert(e);
+    });
+}
+function getAccessToken() {
+  window.alert(liff.getAccessToken());
+}
+function getContext() {
+  window.alert(JSON.stringify(liff.getContext()));
+}
+
+function sendMessage() {
+  liff
+    .sendMessages([{ type: "text", text: "中文測試 Hello from LIFF2.0" }])
+    .then(() => {
+      window.alert("Message has been sent");
+    })
+    .catch(e => {
+      window.alert(e);
+    });
+}
+
+function login() {
+  liff.login();
+}
+
+function scanCode() {
+  liff
+    .scanCode()
+    .then(result => {
+      window.alert(JSON.stringify(result));
+    })
+    .catch(e => {
+      window.alert(e);
+    });
+}
+
+function openWindow() {
+  liff.openWindow({
+    url: "https://sirateek.me",
+    external: true
+  });
+}
+
+function closeWindow() {
+  liff.closeWindow();
+}
+
+function logout() {
+  if (liff.isLoggedIn()) {
+    liff.logout();
+    window.alert("Successfully to Logout");
+    location.reload();
+  }
+}
+
+
+function createFlexMessageData() {
+  var flex = {
+      "type": "flex",
+      "altText": redistitle,
+      "contents": redisdata,
+    };
+
+  return flex;
+}
+
+ var redisdata='';
+
+function shareTargetPicker() {
+  
+  const url = 'https://liff.googo.org:9898/getliff3'
+  axios
+    .get(url)
+    .then(({data}) => {
+      redisdata=data.data;
+      redistitle=data.title;
+      console.log(redistitle);
+      console.log(redisdata);
+
+      liff
+      .shareTargetPicker([
+        createFlexMessageData()      
+      ])
+      .then(() => {
+        alert("Shared to the friend(s) you picked");
+      })
+      .catch(function(res) {
+        alert(res);
+      });
+  
+    });
+
+
+
+}

+ 84 - 0
liff3/js/liff-init.js

@@ -0,0 +1,84 @@
+// ----- Configuration Zone! -----
+// Don't forget to change this to your LIFF ID
+
+const liffId = "1657114132-XEmRVaPz";
+
+// Don't forget to change this to your LIFF ID
+
+liff.init(
+  { liffId: liffId },
+  () => {
+    initLIFF();
+  },
+  err => {
+    window.alert(err);
+  }
+);
+function initLIFF() {
+  if (liff.isLoggedIn()) {
+    liff
+      .getProfile()
+      .then(profile => {
+        document.getElementById("profileImage").src = profile.pictureUrl;
+//        document.getElementById("userId").innerHTML = profile.userId;
+  //      document.getElementById("displayName").innerHTML = profile.displayName;
+  //      document.getElementById("statusMessage").innerHTML =
+    //      profile.statusMessage;
+//        document.getElementById("pictureUrl").href = profile.pictureUrl;
+  //      document.getElementById("pictureUrl").innerHTML = profile.pictureUrl;
+    //    document.getElementById(
+      //    "email"
+      //  ).innerHTML = liff.getDecodedIDToken().email;
+      })
+      .catch(e => {
+      //  document.getElementById("userId").innerHTML = "No data, " + e;
+      //  document.getElementById("displayName").innerHTML = "No data, " + e;
+      //  document.getElementById("statusMessage").innerHTML = "No data, " + e;
+       // document.getElementById("pictureUrl").innerHTML = "No data, " + e;
+        //document.getElementById("email").innerHTML = "No data, " + e;
+      });
+  } else {
+//    document.getElementById("userId").innerHTML = "No data, Login first";
+  //  document.getElementById("displayName").innerHTML = "No data, Login first";
+ //   document.getElementById("statusMessage").innerHTML = "No data, Login first";
+  //  document.getElementById("pictureUrl").innerHTML = "No data, Login first";
+  //  document.getElementById("email").innerHTML = "No data, Login first";
+  }
+
+//  document.getElementById("getOS").innerHTML = liff.getOS();
+  //document.getElementById("getLanguage").innerHTML = liff.getLanguage();
+ // document.getElementById("getVersion").innerHTML = liff.getVersion();
+ // document.getElementById("isInClient").innerHTML = liff.isInClient();
+  //document.getElementById("isLoggedIn").innerHTML = liff.isLoggedIn();
+  var context = liff.getContext();
+  if (context !== null) {
+//    document.getElementById("context_type").innerHTML = context.type;
+ //   document.getElementById("context_viewType").innerHTML = context.viewType;
+  //  document.getElementById("context_userId").innerHTML = context.userId;
+    if (context.utouId) {
+//      document.getElementById("context_utouId").innerHTML = context.utouId;
+    } else {
+ //     document.getElementById("context_utouId").innerHTML =
+  //      "You are not in the utou";
+    }
+    if (context.roomId) {
+//      document.getElementById("context_roomId").innerHTML = context.roomId;
+    } else {
+ //     document.getElementById("context_roomId").innerHTML =
+  //      "You are not in the room";
+    }
+    if (context.groupId) {
+  //    document.getElementById("context_groupId").innerHTML = context.groupId;
+    } else {
+  //    document.getElementById("context_groupId").innerHTML =
+   //     "You are not in the group ";
+    }
+  } else {
+ //   document.getElementById("context_type").innerHTML = "No data.";
+  //  document.getElementById("context_viewType").innerHTML = "No data.";
+   // document.getElementById("context_userId").innerHTML = "No data.";
+   // document.getElementById("context_utouId").innerHTML = "No data.";
+    //document.getElementById("context_roomId").innerHTML = "No data.";
+   // document.getElementById("context_groupId").innerHTML = "No data.";
+  }
+}

+ 8 - 0
main.py

@@ -16,6 +16,7 @@ app.add_middleware(
     allow_methods=["*"],
     allow_headers=["*"],
 )
+
 @app.get("/getbtn")
 def read_root(request: Request):
     r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
@@ -23,6 +24,13 @@ def read_root(request: Request):
     return json.loads(data)
 
 
+@app.get("/liff3")
+def liff3(request: Request):
+    r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')
+    data=r.get('liff3')
+    return json.loads(data)
+
+
 if __name__ == "__main__":
     uvicorn.run("main:app", host="0.0.0.0", port=9898,ssl_keyfile='/etc/letsencrypt/live/liff.googo.org/privkey.pem',ssl_certfile='/etc/letsencrypt/live/liff.googo.org/cert.pem')
 #--ssl-keyfile=/etc/letsencrypt/www.choozmo.com/privkey1.pem --ssl-certfile=/etc/letsencrypt/www.choozmo.com/cert1.pem