-
Notifications
You must be signed in to change notification settings - Fork 0
/
class_test.html
105 lines (86 loc) · 5.26 KB
/
class_test.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Class test</title>
</head>
<body>
<script>
class OneHundredCodeDays {
constructor(date, num = 1){
this.startDate = new Date(date);
this.endDate = new Date(date);
this.startDate.setDate(date.getDate()-(parseInt(num)-1)); //parse int just incase we got it from a string
this.endDate.setDate(date.getDate()+(100-parseInt(num)));
}
dateOf(num){
let date = new Date(this.startDate);
date.setDate(this.startDate.getDate()+parseInt(num)-1)
return date;
}
numberOf(date){
return Math.floor((date-this.startDate)/86400000) + 1;
}
participants(participants){
this.participants = [...participants];
}
}
const searchString = (obj)=>{ //change to a class since we are making an object after all
since = obj.since || "";
until = obj.until || "";
range = obj.range || "";
num = obj.num || "";
participants = obj.participants || "";
if (range!="" && until != ""){ return "error, you can't have a 'range' and an 'until' value. You must have one or the other"}
const formatDate = (date)=>{
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDay();
return `${year}-${month}-${day}`;
}
let search = {}
//set search string for participants
if (participants !== ""){
search.participants = participants.reduce(((a,c,i)=>{
let x;
i==1? x =`from:${a}, OR from:${c}` : x = `${a}, OR from:${c}`;
return x;
}))
}
//set search String for date range
//since
if(since != "") search.since = `since:${formatDate(since)}`;
const untilDate = ()=>{
//until using until or range value
if(until != ""){
return until;
} else if (range == "" && until == ""){
return (new Date()).setDate(since.getDate()+1);
} else if (range != ""){
return (new Date()).setDate(since.getDate()+range);
}
}
search.until = `until: ${formatDate(untilDate())}`;
//get query with day number
if (num!=""){
search.number = `(Day${num} OR “day ${num}” OR r1d${num} OR “r1 d${num}”)`;
}
//could we do the below with dot chaining:
search.url = (...args)=>{
const string = args.join(' ') + ` #100DaysOfCode`;
const urlStart = "https://twitter.com/search?f=tweets&vertical=default&q="
const url = encodeURI(string).replace(/[(]/g, '%28').replace(/[)]/g, '%29').replace(/[#]/g, '%23').replace(/[:]/g, '%3A')
return urlStart + url;
}
return search;
}
const now = new Date();
const myStart = new Date(2019,00,01);
const mySetOf100 = new OneHundredCodeDays(myStart);
mySetOf100.participants(["DashBarkHuss","Dominus_Kelvin","mahakothuri","furryronin","BillRobitskeJr","agatakozinska","wirtzdan","iameduardolopez","Kabuk1","EriPDev","antonioluisgil","IdrisDiba","simoncordova123","Bollybkampo","lksngy","wblancha","asucarlos1","Nanahawau__","M_sameer007","mowinik","its_kyle_yoo","RitaLeverett","mahamat_legrand","khip1994","FilipeEstacio","bio_kath","the_moisrex","sharifa_alabry","ev_burrell","0033Ricca","JenEColbert","AryanDadheech3","ibadi_1","mijoe","science_biatch","Cphoto21","naveddeshmukh","Robert_Elliott_","r4casper","sophiecantype","iameddieyayaya","walpolesj","RaahulIm","danijmoss","lomyenSEA","Piyush_0108","erol_aliyev","JKarena7","KharyaSahil","maheimaa","aid_jww","TheRohitDas","omprakash___","AlwinRivera","dan0mah","shuv1824","ekcenier","vivianychen","Dinesh48185069","IbrahimH_ss_n","camcodes","CJ71585025","sarabome","y_behailu","KristenTruempy","KaustubhMishal","CiccioAmato7","Usheninte","arpancodes","VarshitAgarwal2","Frunkul","moko__co","nikhiljain61019","techieEliot","notakshayb","thatCoding_Yogi","DedVampire","Koji_JUNIA","AdhithyanVijay","leeto","17000973","geekytechiechic","hobo_take","RichishJain","YA_cfc14","tommy6073","ryo0111hk","isagi","iSuvm","RabbaniMuzakky","PremanshuPareek","NaveenEdala","MclDrew","furryronin","sac_180822","imasyou718","kiing_edy","tea_koshi","mikeattara","serial_chiller5","iHrishi_mane","MsMaverickk","hanacaraka","LagisquetB","kmelow1","LachlanEagling","ChetanT50970795","merci_good","vegaaSA","abba_xee","adiojha933","Anko1418","iliyasshahapure","SonOfAziza","moko__co","Yinkxz","frozencerebrum","root_ansh","Usheninte","arnay07"])
// mySetOf100.participants(["DashBarkHuss","Dominus_Kelvin","mahakothuri"]);
let search = searchString({since : mySetOf100.startDate, until: mySetOf100.dateOf(10), participants: mySetOf100.participants, num: 3})
</script>
</body>
</html>