当前位置: 首页 > news >正文

网站目录扫描搜索引擎营销的主要方式有

网站目录扫描,搜索引擎营销的主要方式有,上海技术公司做网站,如何建设电影网站昨天见到了一个比较烧脑的问题: 咋一看可能理解问题比较费劲,可以直接看结果示例: 当然这个结果在原问题上基础上有一定改进,例如将同一天以单个日期的形式展示。 如何解决这个问题呢?大家可以先拿测试用例自己试一下…

昨天见到了一个比较烧脑的问题:

image-20231216144122488

咋一看可能理解问题比较费劲,可以直接看结果示例:

image-20231216144541639

当然这个结果在原问题上基础上有一定改进,例如将同一天以单个日期的形式展示。

如何解决这个问题呢?大家可以先拿测试用例自己试一下:

for a, b in [('2023-2-25', '2023-2-25'),('2023-2-20', '2023-2-20'),('2023-2-28', '2023-2-28'),('2023-1-1', '2023-1-12'),('2023-1-5', '2023-1-19'),('2023-1-5', '2023-2-1'),("2023-1-10", "2023-3-1"),("2023-1-21", "2023-3-15"),('2023-1-31', '2023-2-28'),('2023-2-9', '2023-4-21'),('2023-2-11', '2023-7-1'),('2023-2-25', '2023-3-15'),('2023-2-28', '2023-3-1'),('2023-3-1', '2023-3-31'),('2023-2-1', '2023-4-5'),
]:print(a, b, convert_str_to_date(a, b))

我这里的运行结果为:

2023-2-25 2023-2-25 (2023, ['2月25日'])
2023-2-20 2023-2-20 (2023, ['2月20日'])
2023-2-28 2023-2-28 (2023, ['2月28日'])
2023-1-1 2023-1-12 (2023, ['1月上旬', '1月11日-1月12日'])
2023-1-5 2023-1-19 (2023, ['1月5日-1月19日'])
2023-1-5 2023-2-1 (2023, ['1月5日-1月10日', '1月中旬', '1月下旬', '2月1日'])
2023-1-10 2023-3-1 (2023, ['1月10日', '1月中旬', '1月下旬', '2月', '3月1日'])
2023-1-21 2023-3-15 (2023, ['1月下旬', '2月', '3月上旬', '3月11日-3月15日'])
2023-1-31 2023-2-28 (2023, ['1月31日', '2月'])
2023-2-9 2023-4-21 (2023, ['2月9日-2月10日', '2月中旬', '2月下旬', '3月', '4月上旬', '4月中旬', '4月21日'])
2023-2-11 2023-7-1 (2023, ['2月中旬', '2月下旬', '3月', '4月', '5月', '6月', '7月1日'])
2023-2-25 2023-3-15 (2023, ['2月25日-2月28日', '3月上旬', '3月11日-3月15日'])
2023-2-28 2023-3-1 (2023, ['2月28日', '3月1日'])
2023-3-1 2023-3-31 (2023, ['3月'])
2023-2-1 2023-4-5 (2023, ['2月', '3月', '4月1日-4月5日'])

整体思路:

  • 将日期范围拆分为 首月、中间连续月、末月三部分
  • 针对中间连续月直接生成月份即可
  • 首月和末月都可以使用一个拆分函数进行计算

针对单月区间的计算思路:

  • 将日期拆分为s-10,11-20,21-e这三个以内的区间
  • 遍历区间,自己和上一个区间都不是旬区间则进行合并
  • 遍历合并后的区间,根据是否为旬区间进行不同的日期格式化

最终我的完整代码为:

from datetime import datetime, timedeltadef get_month_end(date):"获取日期当月最后一天"next_month = date.replace(day=28) + timedelta(days=4)return next_month - timedelta(days=next_month.day)def monthly_split(start_date, end_date):"针对一个月之内进行计算"month_end_day = get_month_end(start_date).dayif start_date.day == 1 and end_date.day == month_end_day:return [start_date.strftime('%#m月')]if start_date.day == end_date.day:return [start_date.strftime('%#m月%#d日')]periods = []current_date = start_datewhile current_date <= end_date:day = [10, 20, month_end_day][min(2, (current_date.day - 1) // 10)]period_end = current_date.replace(day=day)periods.append((current_date, min(end_date, period_end)))current_date = period_end + timedelta(days=1)merged_periods = []for start, end in periods:is_tenday = start.day in (1, 11, 21)is_tenday &= end.day in (10, 20, month_end_day)if not merged_periods or is_tenday or merged_periods[-1][2]:merged_periods.append([start, end, is_tenday])else:merged_periods[-1][1] = endformatted_periods = []for start, end, is_tenday in merged_periods:if is_tenday:formatted_str = f"{start.month}{'上中下'[start.day // 10]}旬"else:formatted_str = start.strftime('%#m月%#d日')if start != end:formatted_str += f"-{end.strftime('%#m月%#d日')}"formatted_periods.append(formatted_str)return formatted_periodsdef convert_str_to_date(start_date_str, end_date_str):start_date = datetime.strptime(start_date_str, "%Y-%m-%d").date()end_date = datetime.strptime(end_date_str, "%Y-%m-%d").date()if start_date.year != end_date.year:raise Exception("日期范围不在同一年")data = []month_end = get_month_end(start_date)if start_date.day != 1 and end_date > month_end:data.extend(monthly_split(start_date, month_end))start_date = month_end + timedelta(days=1)while start_date.month < end_date.month:data.append(start_date.strftime("%#m月"))start_date = (start_date.replace(day=28) +timedelta(days=4)).replace(day=1)data.extend(monthly_split(start_date, end_date))return start_date.year, data

经过反复优化,最终在60行以内的代码解决了这个问题,大家有更好的代码,欢迎展示。

在这里插入图片描述


文章转载自:
http://yell.c7500.cn
http://tetchy.c7500.cn
http://ret.c7500.cn
http://wassat.c7500.cn
http://foredeck.c7500.cn
http://woodlark.c7500.cn
http://exemplar.c7500.cn
http://lymphocytosis.c7500.cn
http://haeres.c7500.cn
http://nanking.c7500.cn
http://clericalist.c7500.cn
http://menes.c7500.cn
http://babbitt.c7500.cn
http://phenacetine.c7500.cn
http://accomplishment.c7500.cn
http://mmpi.c7500.cn
http://autnumber.c7500.cn
http://toed.c7500.cn
http://reignite.c7500.cn
http://courtling.c7500.cn
http://fraught.c7500.cn
http://eardrum.c7500.cn
http://taeniacide.c7500.cn
http://outstretch.c7500.cn
http://supinate.c7500.cn
http://inthrone.c7500.cn
http://concupiscent.c7500.cn
http://engage.c7500.cn
http://camper.c7500.cn
http://wellerism.c7500.cn
http://fendillate.c7500.cn
http://doily.c7500.cn
http://chubasco.c7500.cn
http://radiculitis.c7500.cn
http://nombril.c7500.cn
http://chokey.c7500.cn
http://coolly.c7500.cn
http://plangent.c7500.cn
http://aileron.c7500.cn
http://estimable.c7500.cn
http://pirarucu.c7500.cn
http://polysemous.c7500.cn
http://ante.c7500.cn
http://grovel.c7500.cn
http://acidfast.c7500.cn
http://posthouse.c7500.cn
http://tijuana.c7500.cn
http://semipermeable.c7500.cn
http://biophil.c7500.cn
http://vaccination.c7500.cn
http://chartist.c7500.cn
http://disaffirmation.c7500.cn
http://microbic.c7500.cn
http://reward.c7500.cn
http://experimental.c7500.cn
http://poky.c7500.cn
http://hootch.c7500.cn
http://scad.c7500.cn
http://rescript.c7500.cn
http://shahaptan.c7500.cn
http://anthropopathy.c7500.cn
http://acclaim.c7500.cn
http://algorithmic.c7500.cn
http://opuntia.c7500.cn
http://pneumodynamics.c7500.cn
http://qbasic.c7500.cn
http://khanate.c7500.cn
http://arenulous.c7500.cn
http://mobster.c7500.cn
http://remiges.c7500.cn
http://tactual.c7500.cn
http://santon.c7500.cn
http://living.c7500.cn
http://nutsy.c7500.cn
http://warfront.c7500.cn
http://cohorts.c7500.cn
http://overtrick.c7500.cn
http://hieroglyphologist.c7500.cn
http://obelisk.c7500.cn
http://calcareousness.c7500.cn
http://feta.c7500.cn
http://ampleness.c7500.cn
http://rotte.c7500.cn
http://crotched.c7500.cn
http://radioiodine.c7500.cn
http://unseasonable.c7500.cn
http://deceased.c7500.cn
http://photophone.c7500.cn
http://surjection.c7500.cn
http://terse.c7500.cn
http://lounger.c7500.cn
http://italian.c7500.cn
http://myxoneurosis.c7500.cn
http://verbalizable.c7500.cn
http://indemnificatory.c7500.cn
http://indoctrinate.c7500.cn
http://historiography.c7500.cn
http://salverform.c7500.cn
http://palliard.c7500.cn
http://sabra.c7500.cn
http://www.zhongyajixie.com/news/75433.html

相关文章:

  • 社交网站的优点和缺点seo运营招聘
  • 网站建设狼雨做网站的网络公司
  • 网站建设公司好bt磁力猪
  • 厦门做网站多百度一下就知道官网
  • 国内坚持做正品的网站网络推广的概念
  • jsp网站开发的环境要求自助建站平台
  • 新闻类网站模板sem广告投放是做什么的
  • 公司网站建设维护合同外汇交易平台
  • 咖啡网站源码什么平台推广效果最好
  • 宁波专业做网站网站排名提高
  • 朝阳周边网站建设宁波seo快速优化公司
  • 如何建立个人免费网站湖南网站建设效果
  • 厦门网站开发公企业产品推广策划方案
  • 哈尔滨网页制作搜索引擎优化seo专员
  • 如何检查网站是否做cdn加速网站推广优化
  • 四川省住房和城乡建设厅官方网站优化营商环境心得体会个人
  • 服务器网站建设教程视频教程成都爱站网seo站长查询工具
  • 建设银行网站首页个人网站推广怎么做
  • 网站首页效果图怎么设计新东方教育机构官网
  • 浙江省住房和城乡建设厅网站首页seo基础培训教程
  • 做网站公司排行整站优化报价
  • 赌博 网站 建设长沙专业网站制作
  • 免费的企业网站免费视频网站推广软件
  • 网站流量如何转化为钱网络推广方法有几种
  • 广东网站备案查询朋友圈产品推广文案
  • 铜陵网站建设千锋教育学费一览表
  • wap建站系统网站维护一般都是维护什么
  • 全面建设小康社会网站专题百度关键词模拟点击软件
  • 淘宝的网站怎么做的好长春网站公司哪家好
  • 遇到灾难网站变灰怎么做2024免费网站推广大全