SCC 212 - Advanced Programming

Requirements

0. Demo

overview

Two websites with different styles:

1. Database (SQL)

Query from your own database

Reference:

2. API Server (Java)

Recommended framework and package manager:

Reference

3. Online Monitor (JavaScript)

You may choose your favorite, but the final demo should be compatible with Chrome,Firefox

Reference

4. Docker

It’s much better if you can publish your work as a docker image。

Reference:

Serverless (function)

FaaS (Function as a Service) is taking on the trend recently. If you are interested, you may try AWS Lambda or knative.

Here’s an example serverless function deployed on Tecent Cloud with Nodejs8.9 triggered by API Gateway:

腾讯云函数

const request = require('request')

async function getDxyData() {
  try {
    const body = await new Promise(
      (resolve, reject) => {
        request({
          method: 'GET',
          uri: 'https://ncov.dxy.cn/ncovh5/view/pneumonia'
        }, (error, response, body) => {
          if (error) return reject(error)
          resolve(body)
        })
      }
    )
    
    const statistics = JSON.parse(/getStatisticsService\s*=\s*(.*?)}catch/.exec(body)[1])

    const timeline = JSON.parse(/getTimelineService\S*\s*=\s*(.*?)}catch/.exec(body)[1])

    const areaStatistics = JSON.parse(/getAreaStat\s*=\s*(.*?)}catch/.exec(body)[1])
    let listByArea = areaStatistics.map((x) => {
      return {
        provinceName: x.provinceName,
        provinceShortName: x.provinceShortName,
        tags: x.tags,
        confirmed: x.confirmedCount,
        suspected: x.suspectedCount,
        cured: x.curedCount,
        dead: x.deadCount,
        comment: x.comment,
        cities: x.cities.map((x) => {
          return {
            cityName: x.cityName,
            confirmed: x.confirmedCount,
            suspected: x.suspectedCount,
            cured: x.curedCount,
            dead: x.deadCount
          }
        })
      }
    })

    let listByOther = JSON.parse(/getListByCountryTypeService\S*\s=\s*(.*?)}catch/.exec(body)[1])
    listByOther = listByOther.map((x) => {
      return {
        provinceId: x.provinceId,
        provinceName: x.provinceName,
        provinceShortName: x.provinceShortName,
        tags: x.tags,
        confirmed: x.confirmedCount,
        suspected: x.suspectedCount,
        cured: x.curedCount,
        dead: x.deadCount,
        comment: x.comment,
        createTime: x.createTime,
        modifyTime: x.modifyTime,
      }
    })

    return {
      readme: {
        source: 'https://ncov.dxy.cn/ncovh5/view/pneumonia',
        statistics: 'Summary',
        listByArea: 'Domestic',
        listByOther: 'Overseas',
        timeline: 'News'
      },
      statistics,
      listByArea,
      listByOther,
      timeline
    }
  } catch (err) {
    console.log(err)
    return null
  }
}

exports.main_handler = async (event, context, callback) => {
  const data = await getDxyData()
  if (!data) return { error: 1, message: 'Load Failed' }
  return { error: 0, message: '', data }
}

API Address:

https://service-j6saayzy-1252843818.gz.apigw.tencentcs.com/release/covid19

Reference

Version Control (Git)

Use git to manage your project.