Python判断日期是否为休息日并做成日历表

pycharm安装chinesecalender ,file-setting-python interpreter加号找chinesecalender 然后安装

from pyspark.sql import SparkSession
from pyspark.sql.types import IntegerType
import sys
from datetime import datetime
from chinese_calendar import is_workday

def judge_workday(a):
  # str转date类型  如果是date类型可直接传入
  a=datetime.strptime(a, '%Y-%m-%d').date()
  duration = 0  # 初始化  工作日
  if is_workday(a):
    duration=1
  else:
    duration=0
  return duration

# date = datetime.datetime.now().date()
# date='2023-04-23'
# print(judge_workday(date))

if __name__ == "__main__":
    # .master("local") \
    spark = SparkSession.builder \
        .appName("makeCalender") \
        .enableHiveSupport() \
        .getOrCreate()

    spark.udf.register("udf_judge_workday", judge_workday, returnType=IntegerType())  # 注册函数(仅能在sql中使用)

    azkaban_date = sys.argv[1

你可能感兴趣的:(Hive,Python,python,开发语言)