| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- const express = require('express')
- const app = express()
- const axios = require('axios')
- const query = require('./mysqler')
- const bodyParser = require("body-parser");
- const schedule = require('node-schedule');
- const data = ['3948352701','5208966720','2589432731','3917225829','3231047610','1005570772','2448184413','5667617555','1785533160','5672166950','5668213132','5357670210','5625133989','5178549320','3054615393','5973233937','5973637065','6003809445','1988127344','6017601357','6359395544','5972859195','5664785772','5305147245','6030122701','6026399343','2960359192','3280880197','2295650225','6017599835','5971792547','5669689463','5669328912','2253203771','6359373279','6031302315','5719743142','6039760659','1822890914','6030402215','6030660675','2782636765','6039367340','6361527487','6356947724'];
- app.use('/', express.static(__dirname + '/'))
- app.use(bodyParser.urlencoded({ extended: false }));
- // app.all('*', (req, res, next) => {
- // res.header("Access-Control-Allow-Origin", req.headers.origin); //设置来源
- // res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
- // res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
- // res.header("Access-Control-Max-Age", "604800000");
- // res.header("Access-Control-Allow-Credentials", true);
- // res.header("X-Powered-By", ' 3.2.1');
- // // res.header("Content-Type", "application/json;charset=utf-8");
- // next();
- // });
- const httpreq = async (msg) => {
- try {
- let {data} = await axios({
- method: 'get',
- url: 'https://m.weibo.cn/api/container/getIndex?type=uid&value=' + msg
- });
- let redata = {
- weiboname: data.data.userInfo.screen_name,
- weiboid: msg,
- weibofan: data.data.userInfo.followers_count,
- weibopost: data.data.userInfo.statuses_count
- }
- return redata
- } catch (error) {
- console.log(error)
- }
- }
- Date.prototype.format = function (fmt) {
- var o = {
- "M+": this.getMonth() + 1, //月份
- "d+": this.getDate(), //日
- "h+": this.getHours(), //小时
- "m+": this.getMinutes(), //分
- "s+": this.getSeconds(), //秒
- "q+": Math.floor((this.getMonth() + 3) / 3), //季度
- "S": this.getMilliseconds() //毫秒
- };
- if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
- for (var k in o)
- if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
- return fmt;
- }
- const retime = (msg) => {
- var day1 = new Date();
- day1.setDate(day1.getDate() + msg);
- var s1 = day1.format("yyyy-MM-dd")
- return s1
- }
- const inssql = (msg) => {
- try {
- let sql = "INSERT INTO `digital`(`name`, `id`, `fan`, `time`, `post`) VALUES ('"+msg.weiboname+"', '"+msg.weiboid+"', '"+msg.weibofan+"', NOW(), '"+msg.weibopost+"');"
- query(sql, [1], function(err,results,fields){
- });
- } catch (error) {
- console.log(error)
- }
- }
- const select = (t1, t2, callback) => {
- try {
- let time1 = retime(t1)
- let time2 = retime(t2)
- let sql = "SELECT * FROM digital WHERE time BETWEEN '"+ time1 +"' and '"+ time2 +"';"
- query(sql, [1], function(err,results,fields){
- callback(results)
- });
- } catch (error) {
- console.log(error)
- }
- }
- const selintime = (msg, callback) => {
- try {
- let sql = "select * from digital where DATE(time) = '"+ msg +"';"
- query(sql, [1], function(err,results,fields){
- callback(results)
- });
- } catch (error) {
-
- }
- }
- const selintimeer = (callback) => {
- try {
- let sql = "SELECT * FROM `digital` WHERE DATE_FORMAT( time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' ) ORDER BY id;"
- query(sql, [1], function(err,results,fields){
- callback(results)
- });
- } catch (error) {
-
- }
- }
- const selintimeer2 = (tm1, tm2, callback) => {
- try {
- let sql = "select * from `digital` where time BETWEEN '"+tm1+"' and '"+tm2+"' ORDER BY id;"
- query(sql, [1], function(err,results,fields){
- callback(results)
- });
- } catch (error) {
-
- }
- }
- const start = () => {
- data.map(async(i) => {
- let data = await httpreq(i)
- console.log('每日更新完毕')
- inssql(data)
- })
- }
- schedule.scheduleJob('30 1 8 * * *', function(){
- start()
- });
- app.get('/getIndex', async (req, res) => {
- select(0, 1, (msg1)=>{
- select(1, 2, (msg2)=>{
- res.send({
- d1: msg1,
- d2: msg2
- })
- })
- })
- })
- app.get('/gettime', (req, res) => {
- let time = req.query.time;
- selintime(time,(results)=> {
- res.send(results)
- })
- })
- app.get('/all', (req, res) => {
- selintimeer((results)=> {
- res.send(results)
- })
- })
- app.get('/setime', (req, res) => {
- let time1 = req.query.starttime;
- let time2 = req.query.endtime;
- selintimeer2(time1,time2,(msg)=>{
- res.send(msg)
- })
-
- })
- app.listen(2080, function() {
- console.log('http://localhost:2080');
- })
|