forked from lmccay4/TwitterFollowerMonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwitter.cs
111 lines (96 loc) · 3.48 KB
/
Twitter.cs
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
using System;
using System.Threading;
using System.Linq;
using System.Collections.Generic;
using Tweetinvi;
namespace NoahnFollowers
{
public class Twitter
{
public static void MonitorFollowers()
{
List<string> f1List = new List<string>();
List<string> f2List = new List<string>();
Auth.SetUserCredentials("CONSUMER KEY", "CONSUMER SECRET KEY", "USER ACCESS TOKEN", "USER SECRET ACCESS TOKEN");
var user = User.GetAuthenticatedUser();
long noahID = 0; //TRACKED ACCOUNT TWITTER ID HERE
var noah = User.GetUserFromId(noahID);
//--- Gets first list of followers
var followers1 = noah.GetFollowers(500);
foreach (var follower in followers1)
{
f1List.Add(follower.ScreenName);
}
Console.WriteLine(DateTime.Now + " - Watching for unfollowers (12 hours)...");
Thread.Sleep(43200000);
//--- Gets second list of followers
var followers2 = noah.GetFollowers(500);
foreach (var follower in followers2)
{
f2List.Add(follower.ScreenName);
}
//--- This gets the names of unfollowers
#region Unfollowers
var unfollowersList = f1List.Except(f2List).ToList();
string unfollowers = null;
bool unfollowed = false;
if (unfollowersList.Count > 1)
{
foreach (var unfollower in unfollowersList)
{
unfollowers += "@" + unfollower + ", ";
}
unfollowed = true;
}
else if (unfollowersList.Count == 1)
{
unfollowers = "@" + unfollowersList[0];
unfollowed = true;
}
#endregion
//--- This gets the names of new followers
#region New Followers
var newFollowersList = f2List.Except(f1List).ToList();
string newFollowers = null;
bool followed = false;
if (newFollowersList.Count > 1)
{
foreach (var newFollower in newFollowersList)
{
newFollowers += "@" + newFollower + ", ";
}
followed = true;
}
else if (newFollowersList.Count == 1)
{
newFollowers = newFollowersList[0];
followed = true;
}
#endregion
//--- Emails the results
string text = null;
string subject = null;
if (unfollowed && followed)
{
subject = "New Followers And Unfollowers";
text = $"For every loss there is a new beginning. Welcome aboard {newFollowers} and farewell {unfollowers}";
}
else if (unfollowed)
{
subject = "New Unfollower";
text = $"Uff, looks like {unfollowers} unfollowed you. You're better off without em.";
}
else if (followed)
{
subject = "New Follower!";
text = $"Welcome aboard {newFollowers}!";
}
else
{
subject = "All Quiet On The Twitter Front...";
text = "No new followers or unfollowers today.";
}
Emailer.SendEmail(subject, text);
}
}
}