【发布时间】:2021-11-05 16:04:09
【问题描述】:
在下面的脚本中,我手动将字符串值分配给 4 个变量(学院、部门、课程、部门)。
import pandas as pd
def open_seats(request):
college = "ENG"
department = "EC"
course = "414"
section = "A1"
url = 'https://www.bu.edu/link/bin/uiscgi_studentlink.pl/1630695081?ModuleName=univschr.pl&SearchOptionDesc=Class+Number&SearchOptionCd=S&KeySem=20223&ViewSem=Fall+2021&College=' \
+ college + '&Dept=' + department + '&Course=' + course + '&Section=' + section
table = pd.read_html(url)[4]
class_table = table['Class']
open_seats_table = table['OpenSeats']
new_table = pd.concat([class_table, open_seats_table], axis=1)
full_section_string = college + '\u00A0' + department + course + '\u00A0' + section
for i in range(len(new_table)):
if new_table['Class'][i] == full_section_string:
val = new_table['OpenSeats'][i]
break
return val
我想将此脚本连接到要求用户输入这 4 个变量的数据的移动应用程序。因此,与其手动标记它们,我如何为变量分配来自触发器的数据?
起初,我以为数据会以 JSON 格式发送:
{
"college":"ENG",
"department":"EC"
"course":"414",
"section":"A1"
}
所以我将代码更新为如下所示:
def open_seats(request):
college = request["college"]
department = request["department"]
course = request["course"]
section = request["section"]
我对 http 触发器的功能方式以及如何通过 http 触发器将输入传递给云函数缺乏一些基本知识。
【问题讨论】:
-
原来我不了解 URL 参数以及如何查询 URL 中的变量。此链接帮助我解决了我的问题:us-east4-persuasive-yeti-325421.cloudfunctions.net/open_seats.
标签: python google-cloud-functions