Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const axios = require('axios');
- const mysql = require('mysql2');
- var dateFormat = require('dateformat');
- const emailid = [];
- function foreach(arr, func)
- {
- for (var i in arr)
- {
- func(i, arr[i]);
- }
- }
- //tb_email_reminder_2102
- function execute(){
- const connection = mysql.createConnection({
- host: 'localhost',
- user: 'root',
- database: 'v'
- });
- var url = "https://msapi.bankmega.com/email_gtw/email_gateway.php?token=3a7fd845c56b168fea4e67175b024bb9&request_type=get_email";
- var day=dateFormat(new Date(), "dd-mm-yyyy");
- console.log(day)
- var initanggal = day.replace(/\D/g,'');
- console.log(initanggal)
- axios.get(url)
- .then(function(res){
- const emailid = res.data.data[0].email_id;
- let jenis_surat;
- const array = [];
- foreach(res.data.data ,function(i , v){
- const emailid = res.data.data[i].email_id;
- const body = res.data.data[i].body_message;
- // console.log(res.data.data[i].email_id)
- const nomorkartu = res.data.data[i].body_message.split("dengan nomor ")[1].split("dengan jumlah")[0];
- const jatuhtempo = res.data.data[i].body_message.split(" pada tanggal ")[1].split(". Anda bisa melakukan")[0];
- const jumlah_tagihan = res.data.data[i].body_message.split("jumlah tagihan ")[1].split(" akan jatuh ")[0];
- const minimum_pembayaran = res.data.data[i].body_message.split("minimum sebesar ")[1].split(". Abaikan pesan")[0];
- const hitungtempo = jatuhtempo.replace(/\D/g,'');
- if (hitungtempo > initanggal){
- jenis_surat += "AFTER DUE DATE";
- }else{
- jenis_surat += "BEFORE DUE DATE";
- }
- array.push(['1', 'abdulmuttaqin456@gmail.com', 'terkirim', '250 2.0.0 Ok: queued as 685F7...'])
- // console.log(array)
- })
- console.log(jenis_surat)
- const query = "INSERT INTO tb_trans_email_reminder_2102(tb_email_reminder_2102_id, email,status,message) VALUES ?";
- const pool = connection.query(query, [array], function(err, result) {
- if (err) {
- console.log(err)
- }else{
- console.log('result', result)
- }
- })
- })
- }
- execute()
- // console.log(results)
- // console.log(err)
- // })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement