11/07/2020

SQL : SQL Server Enterprise Manager นำเข้าข้อมูลจากการ Query

 SQL : SQL Server Enterprise Manager นำเข้าข้อมูลจากการ Query
โดยการ Query เอาเฉพาะข้อมูลส่วนที่ต่างกัน หรือส่วนที่ไม่มีในอีก Table 1
1. นำ Table ที่ต้องการมาไว้ที่ Database เดียวกัน ด้วยการ copy table และใส่ชื่อต่อท้าย


2. เลือก Table ที่ต้องการ Export
เลือก Source Database
เลือก Destination Database
3. เลือก Use a query to specify the data to transfer.

4. เขียนคำสั่งสำหรับ Query (สามารถไปลองใน SQL ก่อนเพื่อดูความถูกต้องของข้อมูลแล้วค่อย copy มาใส่ก็ได้)
ตัวอย่างคือ เอาข้อมูลที่ไม่มีใน Table2 ไปเทียบกับข้อมูลใน Table1 ใช้ NOT EXISTS

5. เลือก Table destination สามารถกด Preview เพื่อดูข้อมูล หรือกด Transform เพื่อดู File ได้
6. กด Next
7. กด Finish ดูรายระเอียดว่าส่งไปถูกที่หรือไม่
8. ส่งข้อมูลสำเร็จ

10/27/2020

ตัวแปร $S_FinishDate_Edit ยัดเข้า Database

 PHP : การนำวันที่ต่อด้วยเวลาปัจจุบัน และการ Set ค่า NULL เข้าDB
รับ Get หรือ Post มาจาก Form วันที่

  1. list($dd, $mm, $yyyy) = explode("/", $_POST["S_FinishDate_Edit"]);
  2. $S_FinishDate_Edit = "'".$yyyy."-".$mm."-".$dd." ".date("h:i:s")."'";   

ตัวแปร $S_FinishDate_Edit ยัดเข้า Database

การ Set ค่า NULL ให้กับวันที่
ประกาศตัวแปรรับค่า NULL สำคัญต้องใส่ "" ด้วย
  1. $S_FinishDate_Edit = "NULL"


SQL String ไม่ต้องใส่ ' ' หรือ " " ถ้าใส่จะ Error เพราะช่องรับค่า NULL เช่น
  1. $SQL .=" `S_SectionDate`=".$S_SectionDate_Edit.",`S_DoneDate`=".$S_DoneDate_Edit.";


ตัวอย่างใน ข้อเสนอแนะตอนแก้ไข
https://intranet.sci.com/sci/suggestion/qp_start.php?YR=2020

Pi : Pi moition camera notification Line Nofity API

 Pi : Pi moition camera notification Line Nofity API
ติดตั้ง motion
https://intranet.sci.com/blog.php?u=281&b=1667

เพิ่มเติม แก้ Motion ให้ไปเรียกใช้งาน ไฟล์ python ที่สร้างขึ้นเมื่อมีการสร้าง Video

  1. nana /etc/motion/motion.conf

แก้ตรง
on_movie_start python3 /home/pi/line.py


Code pyton ส่ง Line
http://intranet.sci.com/blog.php?u=281&b=1809

Code สำเร็จ
  1. import requests, json
  2. import urllib.parse
  3. import sys
  4.  
  5. import glob
  6. import os
  7. import time
  8.  
  9. LINE_ACCESS_TOKEN = "XXXXXXX"
  10.  
  11. URL_LINE = "https://notify-api.line.me/api/notify"
  12.  
  13. def line_text(message):
  14.     msg = urllib.parse.urlencode({"message":message})
  15.     LINE_HEADERS = {'Content-Type':'application/x-www-form-urlencoded',"Authorization":"Bearer "+LINE_ACCESS_TOKEN}
  16.     session = requests.Session()
  17.     session_post = session.post(URL_LINE, headers=LINE_HEADERS, data=msg)
  18.     print(session_post.text)
  19.  
  20. def line_pic(message, path_file):
  21.     file_img = {'imageFile': open(path_file, 'rb')}
  22.     msg = ({'message': message})
  23.     LINE_HEADERS = {"Authorization":"Bearer "+LINE_ACCESS_TOKEN}
  24.     session = requests.Session()
  25.     session_post = session.post(URL_LINE, headers=LINE_HEADERS, files=file_img, data=msg)
  26.     print(session_post.text)
  27.  
  28. list_of_files = glob.glob('/home/pi/Monitor/*.jpg')
  29. latest_file = max(list_of_files, key=os.path.getctime)
  30. #print(latest_file)
  31. text_send = "Motion Detect OD."
  32. line_pic(text_send, latest_file)
  33.  
  34. #//// Delete All File In Folder Monitor ////#
  35. parth = "/home/pi/Monitor/"
  36. for i in os.listdir ( parth ):
  37.     os.remove(parth+i)

ส่งข้อความเข้า Line Bot ด้วย Sell Script ส่งหา UID ของแต่ละ User ทีละหลาย ๆ User

 ส่งข้อความเข้า Line Bot ด้วย Sell Script ส่งหา UID ของแต่ละ User ทีละหลาย ๆ User
XXX : Token Line Bot
UID = User ID Line
Code

  1. #!/bin/sh
  2. curl -v -X POST https://api.line.me/v2/bot/message/multicast \
  3. -H 'Content-Type: application/json' \
  4. -H 'Authorization: Bearer {XXX}' \
  5. -d '{
  6.     "to": ["UID","UID2","UID2"],
  7.     "messages":[
  8.         {
  9.             "type":"text",
  10.             "text":"Hello, world1"
  11.         },
  12.         {
  13.             "type":"text",
  14.             "text":"Hello, world2"
  15.         }
  16.     ]
  17. }'

Line : Python ส่งรูปเข้า Line API

 Line : Python ส่งรูปเข้า Line API
โปรแกรมที่ต้องใช้ ในเครื่อง rasberry pi
- python 3 ขึ้นไป
- ติดตั้ง

  1. pip install requests

- ติดตั้ง pip
  1. wget "https://bootstrap.pypa.io/get-pip.py"
  2. sudo python get-pip.py


1. เปิดใช้งาน Token ที่ https://notify-bot.line.me/
สามารถทำเป็น User หรือ ทำเป็น Group ก็ได้

*** สำคัญต้องเอา LINE Notify เข้าไปใน Group ด้วย ถึงจะส่งข้อความได้ ***

2. สร้าง Code python line.py
XXXX คือ Token ที่ได้จากข้อ 1.
Code
  1. import requests, json
  2. import urllib.parse
  3. import sys
  4.  
  5. LINE_ACCESS_TOKEN = "XXXX" #Use Token Or Group Token https://notify-bot.line.me/
  6.  
  7. URL_LINE = "https://notify-api.line.me/api/notify"
  8.  
  9. def line_text(message):
  10.     msg = urllib.parse.urlencode({"message":message})
  11.     LINE_HEADERS = {'Content-Type':'application/x-www-form-urlencoded',"Authorization":"Bearer "+LINE_ACCESS_TOKEN}
  12.     session = requests.Session()
  13.     session_post = session.post(URL_LINE, headers=LINE_HEADERS, data=msg)
  14.     print(session_post.text)
  15.  
  16. def line_pic(message, path_file):
  17.     file_img = {'imageFile': open(path_file, 'rb')}
  18.     msg = ({'message': message})
  19.     LINE_HEADERS = {"Authorization":"Bearer "+LINE_ACCESS_TOKEN}
  20.     session = requests.Session()
  21.     session_post = session.post(URL_LINE, headers=LINE_HEADERS, files=file_img, data=msg)
  22.     print(session_post.text)
  23.  
  24. if __name__ == "__main__":
  25.     if len(sys.argv) < 3:
  26.         # <Linux>
  27.         # python line.py "Test"
  28.         line_text(sys.argv[1])
  29.     else:
  30.         # <Linux>
  31.         # python line.py "Test" "/home/pi/test.jpg"
  32.         line_pic(sys.argv[1], sys.argv[2])


3. ทดลองส่งข้อความ
  1. python3 line_group.py "พบการเคลื่อนไหว"

จะมีข้อความแจ้ง
{"status":200,"message":"ok"}

และมีข้อความส่งไป Line

4. ส่งรูปใช้คำสั่ง
  1. python3 line.py "พบการเคลื่อนไหว" "/home/pi/3923-7.jpg"


ส่วนตัว Line Bot จะส่งได้เฉพาะรูปที่ผ่าน Link และต้องเป็น https เมื่อรูปถูกลบหรือเปลี่ยนชื่อ Line จะไม่สามารถแสดงผลรูป
ข้อจำกับ Line notify ส่งได้เดือนละ 1000 ครั้ง
https://notify-bot.line.me/doc/en/

ตัวอย่าง
https://maker.goisgo.net/raspberry-pi-w ... ne-notice/
https://medium.com/@dome.soda125/%E0%B8 ... 8ce98f0bd6
https://medium.com/dolab/blog-7-line-no ... 9724796428
https://engineering.linecorp.com/en/blo ... ad-images/