|
import streamlit as st |
|
import pandas as pd |
|
import numpy as np |
|
import plotly.express as px |
|
import warnings |
|
import re |
|
from zhdate import ZhDate as lunar_date |
|
from typing import Iterable |
|
import streamlit.components.v1 as components |
|
from datetime import datetime |
|
from PIL import Image |
|
warnings.filterwarnings('ignore') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
st.set_page_config( |
|
page_title="simingyanwebpage", |
|
page_icon="🧊", |
|
layout="centered", |
|
initial_sidebar_state="expanded", |
|
menu_items={ |
|
'About': "fyenne@hotmail.com" |
|
} |
|
) |
|
|
|
|
|
|
|
|
|
|
|
@st.cache |
|
class load_data: |
|
''' |
|
read some data |
|
''' |
|
def __init__(self, df, lunar_today, pltdf): |
|
self.df = pd.DataFrame() |
|
self.lunar_today = '' |
|
self.pltdf = pd.DataFrame() |
|
self.chinese_char_map = {} |
|
|
|
|
|
df = pd.read_csv('./dataup/base.csv') |
|
lunar_today = re.sub('\D', '', str(lunar_date.from_datetime(datetime.now()))) |
|
pltdf = pd.DataFrame(data = { |
|
'main': '八卦', |
|
'wuxing':['金', '金', '火', '火', '木', '木', '土', '土','土', '土', '水', '水'], |
|
'bagua': ['乾','兑','离','离','震','巽','坤','坤','艮','艮','坎','坎'], |
|
'tiangan':['庚', '辛','丙', '丁', '甲', '乙', '戊', '己', '戊', '己', '壬', '癸'], |
|
'dizhi':['申', '酉','巳', '午','寅','卯','辰','戌', '丑', '未', '亥', '子'], |
|
'value1': np.repeat(10, 12).tolist() |
|
}) |
|
def plt1(): |
|
fig = px.sunburst(load_data.pltdf, path=['main', 'wuxing', 'bagua', 'tiangan', 'dizhi'], values='value1',\ |
|
color_discrete_sequence = px.colors.qualitative.Pastel2[0:8] |
|
) |
|
return fig |
|
|
|
def count_strokes(words: Iterable) -> int: |
|
""" |
|
统计字符串中所有文字的笔画总数 |
|
|
|
:param words: 需要统计的字符串 |
|
:return: 笔画总数 |
|
""" |
|
chinese_char_map = {} |
|
with open('./dataup/chinese_unicode_table.txt', 'r', encoding='UTF-8') as f: |
|
lines = f.readlines() |
|
for line in lines[6:]: |
|
line_info = line.strip().split() |
|
|
|
chinese_char_map[line_info[0]] = line_info[6] |
|
strokes = 0 |
|
for word in words: |
|
if 0 <= ord(word) <= 126: |
|
strokes += 1 |
|
elif 0x4E00 <= ord(word) <= 0x9FA5: |
|
strokes += int(chinese_char_map.get(word, 1)) |
|
else: |
|
strokes += 1 |
|
return strokes |
|
|
|
|
|
st.title('正德佷准') |
|
st.markdown('--- \n > **人工智能和量子物理结合下的优化版梅花易数**\n ---') |
|
add_selectbox = st.sidebar.selectbox( |
|
"In which aspects would you like to know your future?", |
|
("undefined", "money", "love") |
|
) |
|
|
|
if add_selectbox == 'undefined': |
|
print('') |
|
|
|
with st.container(): |
|
|
|
st.plotly_chart(load_data.plt1()) |
|
|
|
else: |
|
'今日是农历: %s \ |
|
公历 %s'%(load_data.lunar_today, datetime.today().strftime('%Y%m%d')) |
|
dizhi = '酉、戌、亥、子、丑、寅、卯、辰、巳、午、未、申'.split('、') |
|
|
|
dict = dict(zip(range(1,13), "子、丑、寅、卯、辰、巳、午、未、申、酉、戌、亥".split('、'))) |
|
|
|
name = st.text_input('请输入您的姓名') |
|
|
|
components.html("<html><body>笔画数:%s</body></html>"%load_data.count_strokes(name), |
|
width=200, height=30) |
|
|
|
bdate = st.text_input('请输入您的生日', value = '20220304') |
|
dizhi = dizhi[int(bdate[0:4])%12 - 1] |
|
components.html("<html><body>地支: %s</body></html>"%dizhi, |
|
width=200, height=30) |
|
|
|
bt = st.button('测') |
|
if (bt == True) & (name != '') & (int(bdate) < 20220101) & (len(name) < 26): |
|
st.markdown('恭喜您和刘亦菲谈恋爱') |
|
else: |
|
st.text("输入信息有误") |
|
pass |
|
|