This repository has been archived by the owner on Nov 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
125 lines (107 loc) · 3.58 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
var express = require('express');
var request = require('request');
var fs = require('fs');
var passport = require('passport')
, FacebookStrategy = require('passport-facebook').Strategy;
var cookieParser = require('cookie-parser');
var app = express();
var ID = "0";
var cheerio = require('cheerio');
var readlineSync = require('readline-sync');
app.use(cookieParser());
app.use('/static',express.static(__dirname+'/static'));
//my ID : 1388002237882339
passport.use(new FacebookStrategy({
clientID: 1742952685970599,
clientSecret: "2c03c040c02e08e665b9c4d506df66f8",
callbackURL: "http://localhost:8088/auth/facebook/callback",
passReqToCallBack: true
},
function(accessToken, refreshToken, profile, done) {
// console.log(JSON.stringify(profile));
ID = profile.id;
console.log(ID);
// User.findOrCreate({ facebookId:profile.id }, function(err, user) {
// if(err) { return done(err); }
// done(null, user);
// });
done(null);
}
));
// Redirect the user to Facebook for authentication. When complete,
// Facebook will redirect the user back to the application at
// /auth/facebook/callback
app.get('/auth/facebook', passport.authenticate('facebook'));
// Facebook will redirect the user to this URL after approval. Finish the
// authentication process by attempting to obtain an access token. If
// access was granted, the user will be logged in. Otherwise,
// authentication has failed.
app.get('/auth/facebook/callback',
passport.authenticate('facebook', { successRedirect: '/',
failureRedirect: '/' }));
app.post('/append/:code', function(req, res) {
console.log("appendFile");
fs.appendFile(__dirname + '/static/Receipt', req.params.code + '\n' ,'UTF-8', function(err){
if(err){
console.log("Append fail!");
}
})
})
app.post('/parse', function(req, res) {
var code_arr = [];
var my_code = [];
request('http://invoice.etax.nat.gov.tw/', function (error, response, html) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(html);
$(".t18Red").each(function(i, element) {
// console.log($(element).text());
code_arr.push($(element).text());
res = [];
res.push(i.textContent);
});
// console.log($($("h2")['1']).text());
// console.log($($("h2")['3']).text());
}
console.log("#############");
//讀取發票記錄檔
var lineReader = require('readline').createInterface({
input: fs.createReadStream(__dirname + '/static/Receipt')
});
console.log("!!!!!!!!!");
lineReader.on('line', function (line) {
console.log('Line from file:', line);
my_code.push(line);
console.log("my_code 宣告");
}).on('close', () => {
console.log(code_arr.length);
for(var i=0;i<code_arr.length;i++){
console.log(i, code_arr[i]);
}
console.log("特獎 : " + code_arr[0]);
console.log(my_code.length);
//對特獎
for(var i = 0; i<my_code.length ;i++){
console.log("my_code = " + my_code[i]);
if(parseInt(my_code[i]) == parseInt(code_arr[0])){
console.log("中特獎!");
}
}
});
// console.log("?????????");
// while(my_code.length<2){
// console.log("size=" + my_code.length);
// }
// console.log("AAAAAAAAA");
});
})
app.get('/', function(req, res) {
if(ID!="0"){
console.log("Login!");
res.send(fs.readFileSync('./index2.html', 'UTF-8'));
}
else{
console.log("not Login!");
res.send(fs.readFileSync('./index.html', 'UTF-8'));
}
});
app.listen("8088");