Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
flow2000 committed Dec 24, 2022
0 parents commit f29611f
Show file tree
Hide file tree
Showing 15 changed files with 3,360 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/__pycache__/*
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.8.5

COPY . .

RUN pip install -r requirements.txt -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

EXPOSE 8888

CMD ["python", "api/main.py"]
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 每日早报

![news](https://socialify.git.ci/flow2000/news/image?description=1&descriptionEditable=60%E7%A7%92%E8%AF%BB%E6%87%82%E4%B8%96%E7%95%8C%EF%BC%8C%E6%94%AF%E6%8C%81%E4%B8%80%E9%94%AE%E9%83%A8%E7%BD%B2%EF%BC%8C%E5%BF%AB%E9%80%9F%E7%94%9F%E6%88%90%E6%8E%A5%E5%8F%A3%E6%95%B0%E6%8D%AE&font=Inter&language=1&logo=https%3A%2F%2Fnews.panghai.top%2Ffavicon.svg&name=1&owner=1&pattern=Formal%20Invitation&stargazers=1&theme=Light)

#### 简介

60秒读懂世界!

#### Vercel 一键部署(推荐)
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/flow2000/news)

#### Docker 一键部署

```markdown
docker run -itd --name=news --restart=always -p 9134:8888 flow2000/news
```

#### API 说明

GET:`https://news.panghai.top/60s`

##### 请求参数

| 参数名 | 位置 | 类型 | 必填 | 示例值 |说明 |
| :--------------- | :---- | :----- | :--: | :--------------------- | :--------------------- |
| `offset` | `query` | `int` || `0` |说明:`0` 为今天,`1` 为昨天,依次类推 |

17 changes: 17 additions & 0 deletions api/FlowResponse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from fastapi.responses import JSONResponse

def success(msg="操作成功",data=None):
res_json = {}
res_json['code']=200
res_json['msg']=msg
if data!=None:
res_json['data']=data
return JSONResponse(status_code=200, content=res_json)

def error(msg="操作失败",data=None):
res_json = {}
res_json['code']=500
res_json['msg']=msg
if data!=None:
res_json['data']=data
return JSONResponse(status_code=500, content=res_json)
127 changes: 127 additions & 0 deletions api/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# -*- coding:utf-8 -*-
# @Author: flow2000
import requests
import json
import random
import sys
import os
import time

from fastapi import FastAPI,File, UploadFile, Header, Depends, HTTPException
from fastapi.responses import StreamingResponse
from fastapi.responses import RedirectResponse
from fastapi.responses import HTMLResponse
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from colorama import init
init(autoreset=True)

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)

from weibo_api import weibo_api
from bili_api import bili_api
from sixty_api import sixty_api
from api import FlowResponse

VERSION="1.0.0"

app = FastAPI()

# 设置CORS
origins = [
"*"
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

@app.get("/version",tags=["VERSION"], summary="获取版本信息")
async def index():
'''
响应字段说明:
- code:状态码
- msg:部署信息
- current_version:当前版本
- latest_version:最新版本
'''
latest_version=""
try:
latest_version=requests.get('https://static.panghai.top/txt/version/news.txt',timeout=3).text
except Exception as e:
print(e)
return FlowResponse.error(msg="NEWSAPI获取不到最新版本,但仍可使用,请联系:https://github.com/flow2000/news",data={"current_version":VERSION})
data={
"current_version":VERSION,
"latest_version":latest_version
}
return FlowResponse.success(msg="news部署成功,查看接口文档:https://news.panghai.top/docs",data=data)

async def fetch(session, url):
async with session.get(url, verify_ssl=False) as response:
return await response.text()

@app.get("/weibo",tags=["微博热搜API"], summary="获取热搜json数据")
async def weibo():
'''
微博热搜API
'''
res=weibo_api.get_topic()
if res!=None:
return FlowResponse.success(data=res)
else:
return FlowResponse.error('系统发生错误')

@app.get("/bili",tags=["B站热搜API"], summary="获取热搜json数据")
async def bili():
'''
B站热搜API
'''
res=bili_api.get_topic()
if res!=None:
return FlowResponse.success(data=res)
else:
return FlowResponse.error('系统发生错误')

@app.get("/60s",tags=["60秒新闻API"], summary="获取今日新闻json数据")
async def sixty(offset: int = 0):
'''
请求字段说明:
- offset:偏移量(可选参数:0,1,2,3),默认0表示今天,1表示昨天,2表示前天,3表示大前天。
'''
res=sixty_api.get_topic(offset)
if res!=None:
return FlowResponse.success(data=res)
else:
return FlowResponse.error('系统发生错误')

def iterfile(file_path):
with open(file_path, "r", encoding='utf-8') as file_like:
yield from file_like

@app.get("/",tags=["静态资源"], summary="首页", response_class=HTMLResponse)
async def index():
res=''
with open(os.getcwd()+'/index.html', "r", encoding='utf-8') as f:
res=f.read()
f.close()
return res

@app.get("/index.js",tags=["静态资源"], summary="js")
async def js():
return StreamingResponse(iterfile(os.getcwd()+'/index.js'), media_type="application/javascript")

@app.get("/news.css",tags=["静态资源"], summary="css")
async def css():
return StreamingResponse(iterfile(os.getcwd()+'/news.css'), media_type="text/css")

@app.get("/favicon.svg",tags=["静态资源"], summary="图标")
async def favicon():
return StreamingResponse(iterfile(os.getcwd()+'/favicon.svg'), media_type="image/svg+xml")

if __name__ == "__main__":
uvicorn.run("main:app", host="0.0.0.0", port=8888)
29 changes: 29 additions & 0 deletions bili_api/bili_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import requests
import json
import time
API='https://app.bilibili.com/x/v2/search/trending/ranking'
headers={
'Access-Control-Allow-Origin':'*',
'Access-Control-Allow-Headers':'Content-Type',
'Access-Control-Allow-Methods':'*',
'Content-Type':'application/json;charset=utf-8'
}

def get_topic():
try:
dataList=[]
data=requests.get(API,headers=headers,timeout=8)
data=json.loads(data.text)
data_json=data['data']['list']
for i in range(0,len(data_json)):
dic = {
'title': data_json[i].get('show_name',''),
'keyword': data_json[i].get('keyword',''),
'url': 'https://search.bilibili.com/all?keyword=' + data_json[i].get('keyword',''),
'icon': data_json[i].get('icon','')
}
dataList.append(dic)
return dataList
except Exception as e:
print(str(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())),e)
return None
1 change: 1 addition & 0 deletions favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 87 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!doctype html>
<html>

<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width initial-scale=1'>
<title>每日60秒读懂世界!</title>
<meta name="description" content="每天60秒读懂世界,心流博客每天60秒看懂世界频道">
<meta name=viewport content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover">
<script src="https://jsd.onmicrosoft.cn/npm/[email protected]/dist/notiflix-notify-aio-3.2.5.min.js"></script>
<link rel="stylesheet" href="https://jsd.onmicrosoft.cn/npm/[email protected]/dist/notiflix-3.2.5.min.css"></script>
<script src="https://jsd.onmicrosoft.cn/npm/[email protected]/nprogress.js"></script>
<link href="https://jsd.onmicrosoft.cn/npm/[email protected]/nprogress.css" rel="stylesheet" />
<link rel="stylesheet" href="./news.css"/>
<link rel="shortcut icon" href="./favicon.svg">
<!-- 百度统计,可去掉 -->
<script>
var _hmt = _hmt || [];
(function () {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?78565d6c29e30494518f051e7286e173";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
</head>

<body class='typora-export os-windows'>
<div class='typora-export-content'>
<div id='write' class=''>
<h1>
<center>每日早报</center>
</h1>
<blockquote>
<center>
<div id="date">202X年X月X日 星期X 农历X月XX XXXX</div>
<center></center>
</center>
</blockquote>
<ol start='' id="news">
<li>首都各界欢庆北京申办2008年奥运会成功,北京喜获2008年奥运会主办权,谱写奥运史上最壮丽的篇章。</li>
<li>首都各界欢庆北京申办2008年奥运会成功,北京喜获2008年奥运会主办权,谱写奥运史上最壮丽的篇章。</li>
<li>首都各界欢庆北京申办2008年奥运会成功,北京喜获2008年奥运会主办权,谱写奥运史上最壮丽的篇章。</li>
<li>首都各界欢庆北京申办2008年奥运会成功,北京喜获2008年奥运会主办权,谱写奥运史上最壮丽的篇章。</li>
<li>首都各界欢庆北京申办2008年奥运会成功,北京喜获2008年奥运会主办权,谱写奥运史上最壮丽的篇章。</li>
<li>首都各界欢庆北京申办2008年奥运会成功,北京喜获2008年奥运会主办权,谱写奥运史上最壮丽的篇章。</li>
<li>首都各界欢庆北京申办2008年奥运会成功,北京喜获2008年奥运会主办权,谱写奥运史上最壮丽的篇章。</li>
<li>首都各界欢庆北京申办2008年奥运会成功,北京喜获2008年奥运会主办权,谱写奥运史上最壮丽的篇章。</li>
<li>首都各界欢庆北京申办2008年奥运会成功,北京喜获2008年奥运会主办权,谱写奥运史上最壮丽的篇章。</li>
<li>首都各界欢庆北京申办2008年奥运会成功,北京喜获2008年奥运会主办权,谱写奥运史上最壮丽的篇章。</li>
<li>首都各界欢庆北京申办2008年奥运会成功,北京喜获2008年奥运会主办权,谱写奥运史上最壮丽的篇章。</li>
<li>首都各界欢庆北京申办2008年奥运会成功,北京喜获2008年奥运会主办权,谱写奥运史上最壮丽的篇章。</li>
<li>首都各界欢庆北京申办2008年奥运会成功,北京喜获2008年奥运会主办权,谱写奥运史上最壮丽的篇章。</li>
<li>首都各界欢庆北京申办2008年奥运会成功,北京喜获2008年奥运会主办权,谱写奥运史上最壮丽的篇章。</li>
<li>首都各界欢庆北京申办2008年奥运会成功,北京喜获2008年奥运会主办权,谱写奥运史上最壮丽的篇章。</li>
</ol>
<blockquote>
<em>
<center><a><span id="weiyu" onclick="load_yiyan()">自强 民主 文明 和谐</span></a></center>
</em>
</blockquote>
<figure>
<table>
<thead>
<tr>
<th>
<center><button class="button" onclick="before()"><span class="text">前一天</span></button></center>
</th>
<th>
<center><button class="button" onclick="after()"><span class="text">后一天</span></button></center>
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<a href="https://github.com/flow2000/news">
<p style="color: #ff1485;">Made by 心流 ✨.</p>
</a>
</figure>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="./index.js"></script>
</body>

</html>
Loading

1 comment on commit f29611f

@vercel
Copy link

@vercel vercel bot commented on f29611f Dec 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.