我建立了一個小工具(無UI),將接受網絡掛接從幾個服務,將內容重新格式化,然後發送標準化內容到另一個網絡掛接在Python網絡掛接轉換器。最簡單的方式建立在谷歌應用程序引擎
實例:條紋網絡掛接有大量的原始數據,但我想用ping命令總結另一個網絡掛接。所以我想要把原始數據帶給我,將它重新格式化爲一個簡單的字符串,然後發送給另一個webhook。
我想象中的腳本這樣做:
# 1. receive webhook sent to URL with ?service=stripe param
# 2. parse URL to get service param
# 3. parse data received in payload
# 4. use some of the data received in new string
# 5. send string to new webhook
我願意主辦這次在GAE上。我用Django構建了很多項目,但是因爲這不需要看起來很重的UI或數據庫。我很樂意提供任何幫助。我已經得到了GAE項目中建立,而這種狀況:
import web #using web.py
import logging
urls = (
"/.*", "hooks",
)
app = web.application(urls, globals())
class hooks:
# 1. DONE receive webhook sent to URL with ?service=stripe param
def POST(self):
# 2. parse URL to get service param
# ...
# service_name = [parsed service name]
# 3. DONE parse data received in payload
data = web.data()
logging.info(data)
# 4. DONE use some of the data received in new string
# (I've got the reformatting scripts already written)
# data_to_send = reformat(data, service_name)
# 5. send data_to_send as payload to new webhook
# new_webhook_url = 'http://example.com/1823123/'
# CURL for new webhook is: curl -X POST -H 'Content-Type: application/json' 'http://example.com/1823123/' -d '{"text": data_to_send}'
return 'OK'
app = app.gaerun()
所以在GAE上,是有(2)解析進來的URL和(5)發送一個網絡掛接一個優選的方法是什麼?
我會使用webapp2解析傳入的URL以及有效負載(2&3)嗎? – Brenden
@Brenden,更新了答案,以顯示如何使用webapp2獲取有效載荷。 –