@@ -25,60 +25,67 @@ public class MeetupService
25
25
{
26
26
public void UpdateMeetupStats ( )
27
27
{
28
- var configPath = HostingEnvironment . MapPath ( "~/config/MeetupUmbracoGroups.txt" ) ;
29
- // Get the alias (urlname) of each group from the config file
30
- var aliases = File . ReadAllLines ( configPath ) . Where ( x => x . Trim ( ) != "" ) . Distinct ( ) . ToArray ( ) ;
31
-
32
- var counterPath = HostingEnvironment . MapPath ( "~/App_Data/TEMP/MeetupStatisticsCounter.txt" ) ;
33
- var counter = 0 ;
34
- if ( File . Exists ( counterPath ) )
28
+ try
35
29
{
36
- var savedCounter = File . ReadAllLines ( counterPath ) . First ( ) ;
37
- int . TryParse ( savedCounter , out counter ) ;
38
- }
30
+ var configPath = HostingEnvironment . MapPath ( "~/config/MeetupUmbracoGroups.txt" ) ;
31
+ // Get the alias (urlname) of each group from the config file
32
+ var aliases = File . ReadAllLines ( configPath ) . Where ( x => x . Trim ( ) != "" ) . Distinct ( ) . ToArray ( ) ;
39
33
40
- var newCounter = aliases . Length <= counter ? 0 : counter + 1 ;
41
- File . WriteAllText ( counterPath , newCounter . ToString ( ) , Encoding . UTF8 ) ;
34
+ var counterPath = HostingEnvironment . MapPath ( "~/App_Data/TEMP/MeetupStatisticsCounter.txt" ) ;
35
+ var counter = 0 ;
36
+ if ( File . Exists ( counterPath ) )
37
+ {
38
+ var savedCounter = File . ReadAllLines ( counterPath ) . First ( ) ;
39
+ int . TryParse ( savedCounter , out counter ) ;
40
+ }
42
41
43
- var client = new MeetupOAuth2Client ( ) ;
44
- var response = client . DoHttpGetRequest ( string . Format ( "https://api.meetup.com/{0}/events?page=1000&status=past" , aliases [ counter ] ) ) ;
45
- var events = MeetupGetEventsResponse . ParseResponse ( response ) . Body ;
42
+ var newCounter = aliases . Length <= counter ? 0 : counter + 1 ;
43
+ File . WriteAllText ( counterPath , newCounter . ToString ( ) , Encoding . UTF8 ) ;
46
44
47
- var meetupCache = new List < MeetupCacheItem > ( ) ;
48
- var meetupCacheFile = HostingEnvironment . MapPath ( "~/App_Data/TEMP/MeetupStatisticsCache.json" ) ;
49
- if ( File . Exists ( meetupCacheFile ) )
50
- {
51
- var json = File . ReadAllText ( meetupCacheFile ) ;
52
- using ( var stringReader = new StringReader ( json ) )
53
- using ( var jsonTextReader = new JsonTextReader ( stringReader ) )
45
+ var client = new MeetupOAuth2Client ( ) ;
46
+ var response = client . DoHttpGetRequest ( string . Format ( "https://api.meetup.com/{0}/events?page=1000&status=past" , aliases [ counter ] ) ) ;
47
+ var events = MeetupGetEventsResponse . ParseResponse ( response ) . Body ;
48
+
49
+ var meetupCache = new List < MeetupCacheItem > ( ) ;
50
+ var meetupCacheFile = HostingEnvironment . MapPath ( "~/App_Data/TEMP/MeetupStatisticsCache. json" ) ;
51
+ if ( File . Exists ( meetupCacheFile ) )
54
52
{
55
- var jsonSerializer = new JsonSerializer ( ) ;
56
- meetupCache = jsonSerializer . Deserialize < List < MeetupCacheItem > > ( jsonTextReader ) ;
53
+ var json = File . ReadAllText ( meetupCacheFile ) ;
54
+ using ( var stringReader = new StringReader ( json ) )
55
+ using ( var jsonTextReader = new JsonTextReader ( stringReader ) )
56
+ {
57
+ var jsonSerializer = new JsonSerializer ( ) ;
58
+ meetupCache = jsonSerializer . Deserialize < List < MeetupCacheItem > > ( jsonTextReader ) ;
59
+ }
57
60
}
58
- }
59
-
60
- foreach ( var meetupEvent in events )
61
- {
62
- if ( meetupCache . Any ( x => x . Id == meetupEvent . Id ) )
63
- continue ;
64
61
65
- var meetupCacheItem = new MeetupCacheItem
62
+ foreach ( var meetupEvent in events )
66
63
{
67
- Time = meetupEvent . Time ,
68
- Created = meetupEvent . Created ,
69
- Description = meetupEvent . Description ,
70
- HasVenue = meetupEvent . HasVenue ,
71
- Id = meetupEvent . Id ,
72
- Link = meetupEvent . Link ,
73
- Name = meetupEvent . Name ,
74
- Updated = meetupEvent . Updated ,
75
- Visibility = meetupEvent . Visibility
76
- } ;
77
- meetupCache . Add ( meetupCacheItem ) ;
78
- }
64
+ if ( meetupCache . Any ( x => x . Id == meetupEvent . Id ) )
65
+ continue ;
79
66
80
- var rawJson = JsonConvert . SerializeObject ( meetupCache , Formatting . Indented ) ;
81
- File . WriteAllText ( meetupCacheFile , rawJson , Encoding . UTF8 ) ;
67
+ var meetupCacheItem = new MeetupCacheItem
68
+ {
69
+ Time = meetupEvent . Time ,
70
+ Created = meetupEvent . Created ,
71
+ Description = meetupEvent . Description ,
72
+ HasVenue = meetupEvent . HasVenue ,
73
+ Id = meetupEvent . Id ,
74
+ Link = meetupEvent . Link ,
75
+ Name = meetupEvent . Name ,
76
+ Updated = meetupEvent . Updated ,
77
+ Visibility = meetupEvent . Visibility
78
+ } ;
79
+ meetupCache . Add ( meetupCacheItem ) ;
80
+ }
81
+
82
+ var rawJson = JsonConvert . SerializeObject ( meetupCache , Formatting . Indented ) ;
83
+ File . WriteAllText ( meetupCacheFile , rawJson , Encoding . UTF8 ) ;
84
+ }
85
+ catch ( Exception ex )
86
+ {
87
+ LogHelper . Error < MeetupsController > ( "Could not get events from meetup.com" , ex ) ;
88
+ }
82
89
}
83
90
84
91
@@ -95,6 +102,7 @@ public MeetupEventsModel GetUpcomingMeetups()
95
102
if ( File . Exists ( configPath ) == false )
96
103
{
97
104
LogHelper . Debug < MeetupsController > ( "Config file was not found: " + configPath ) ;
105
+
98
106
return meetups ;
99
107
}
100
108
@@ -106,7 +114,6 @@ public MeetupEventsModel GetUpcomingMeetups()
106
114
{
107
115
// Initialize a new service instance (we don't specify an API key since we're accessing public data)
108
116
var service = new Skybrud . Social . Meetup . MeetupService ( ) ;
109
-
110
117
var items = new List < MeetupItem > ( ) ;
111
118
112
119
foreach ( var alias in aliases )
@@ -119,17 +126,19 @@ public MeetupEventsModel GetUpcomingMeetups()
119
126
if ( meetupGroup . JObject . HasValue ( "next_event" ) == false )
120
127
continue ;
121
128
122
- var nextEventId = meetupGroup . JObject . GetString ( "next_event.id" ) ;
123
-
124
129
// Make the call to the Meetup.com API to get upcoming events
125
130
var events = service . Events . GetEvents ( alias ) ;
126
131
127
- // Get the next event(s)
128
- var nextEvent = events . Body . FirstOrDefault ( x => x . Id == nextEventId ) ;
132
+ // Get the events in the next 30 days
133
+ var nextEvents = events . Body . Where ( x => x . Time < DateTime . Now . AddDays ( 30 ) ) ;
129
134
130
- // Append the first event of the group
131
- if ( nextEvent != null )
132
- items . Add ( new MeetupItem ( meetupGroup , nextEvent ) ) ;
135
+ if ( nextEvents . Any ( ) )
136
+ {
137
+ foreach ( var item in nextEvents )
138
+ {
139
+ items . Add ( new MeetupItem ( meetupGroup , item ) ) ;
140
+ }
141
+ }
133
142
}
134
143
catch ( Exception ex )
135
144
{
0 commit comments