第五天:爬蟲【三】


Posted by luckstar77 on 2022-10-27

  • 更新殖利率資料到 mongodb

      const dividendsValues = R.values(dividends);
      if(dividendsValues.length === 0) return;
    
      const dividendsFailureObject = R.filter(value => {
          if(value.length === 1) {
              if(value[0] === DividendState.FAILURE) return true;
              else return false;
          }
    
         return R.any(R.equals(1))( R.splitAt(1, value)[1]);
    
      }, dividends)
      const dividendsFailures = R.keys(dividendsFailureObject);
      const successRate = (1-(dividendsFailures.length / dividendsValues.length))*100.00;
    
      const updated = await mongodbClient.collection(COLLECTION).updateOne({
          id: stockId
      }, {
          $set: { 
              name: stockName, 
              successRate,
              allAvgCashYields,
              allAvgRetroactiveYields,
          },
          $currentDate: { updated: true },
      }, {
          upsert: true,
      })
    
  • 在 redis 新增 STOCK_ID_INDEX 並每次自動新增1次

    await redisClient.incr('STOCK_ID_INDEX');
    
  • 初始化 eslint 設定檔

    {
      "env": {
          "browser": true,
          "es2021": true
      },
      "extends": [
          "eslint:recommended",
          "plugin:@typescript-eslint/recommended"
      ],
      "overrides": [
      ],
      "parser": "@typescript-eslint/parser",
      "parserOptions": {
          "ecmaVersion": "latest",
          "sourceType": "module"
      },
      "plugins": [
          "@typescript-eslint"
      ],
      "rules": {
          "indent": [
              "error",
              4
          ],
          "linebreak-style": [
              "error",
              "unix"
          ],
          "quotes": [
              "error",
              "single"
          ],
          "semi": [
              "error",
              "always"
          ]
      }
    }
    
  • 加入 eslint 設定檔,並新增 .vscode/settings.json

    {
      "editor.codeActionsOnSave": {
          "source.fixAll.eslint": true
      }, //儲存時自動執行 ESLint 格式化
    }
    
  • 增加程式結束點

    if (isNaN(price) || allAvgRetroactiveYields === 0 || isNaN(allAvgRetroactiveYields)) {
          await redisClient.incr('STOCK_ID_INDEX');
          process.exit();
      }
    









Related Posts

React 入門 1 - Element, Function Component, & props

React 入門 1 - Element, Function Component, & props

Android Kotlin-1 基本語法1

Android Kotlin-1 基本語法1

[Day 01] 強化學習?

[Day 01] 強化學習?


Comments