Buổi hôm nay mình có cover các nội dung như sau:
import json
from office365.runtime.auth.user_credential import UserCredential
from office365.sharepoint.request import SharePointRequest
request = SharePointRequest(site_url).with_credentials(UserCredential("{username}", "{password}"))
response = request.execute_request("web")
json = json.loads(response.content)
web_title = json['d']['Title']
print("Web title: {0}".format(web_title))
Rồi từ json data, tạo dataframe như bình thường: df = pd.DataFrame([json])
import pyocdb
# Connect to the database
connection = pyodbc.connect("Driver={Driver_Name};"
"Server=server_name;"
"Database=database_name;"
"UID=user_id;"
"PWD=password;")
# Create a cursor object
cursor = connection.cursor()
# Execute a query
cursor.execute("SQL QUERY")
# Fetch results
rows = cursor.fetchall()
# Process results
for row in rows:
print(row) --------> Từ each row tạo dataframe như bình thường
# Close the connection
connection.close()
import requests
pd.DataFrame([response.text]) ----> Chuyển thành dataframe rồi làm thao tác như bình thường. Nếu data update liên tục thì có thể schedule Python script
****Mình sẽ nói kĩ hơn về DB và API ở bài số 9 nha.
- How to secure our streamlit application (force users to login before accessing to the app)? In every company, users' rights are stored in Mircrosoft's Active Directory (simply speaking, it's something like "phuong@mycompany.com - access to unicorns app"). You can link this authorization to your streamlit app. Check out how to set it up here: https://docs.streamlit.io/develop/api-reference/user/st.login. Phần này khá advance nên mình không có đánh vào trọng tâm khi dạy, nhưng chị An có hỏi mình có thể làm được không vì chị ấy muốn recommend solution này cho công ty của chị.
- Commit code vào git: Bấm Source Control -> Điền tên message -> Bấm commit (như hình) -> Bấm dấu '...' -> Pull, Push -> Push. Làm xong thì code của các bạn sẽ đc update lên trên trang git
- Upload app lên streamlit community: Các bạn bấm vào link này https://share.streamlit.io và sign in vào GitHub của các bạn. Sau đó bấm Create App -> Deploy Public App From GIthub -> điền thông tin về app của các bạn (như trong hình) -> Deploy. Deploy xong các bạn nhớ quay lại project của các bạn trong Github -> Setting (như hình) -> Scroll tới cuối trang rồi bấm change visibility to Private nha. Như vậy thì khi các bạn chia sẻ streamlit link, code của các bạn sẽ được bảo mật, tránh việc bị đạo code nhen.
- Mình cũng có thông báo phát động cuộc thi giữa các học viên để các bạn có động lực làm bài, chi tiết mình sẽ post ở một post riêng nha :)
Merci các bạn