This repository was archived by the owner on Apr 28, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
77 lines (67 loc) · 2.64 KB
/
Copy pathProgram.cs
File metadata and controls
77 lines (67 loc) · 2.64 KB
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using PoliticalTweetsImporter.Models;
namespace PoliticalTweetsImporter
{
public sealed class Program
{
public static void Main( string[] args )
{
Process();
Console.WriteLine( "Done." );
Console.Read();
}
private static void DownloadTweets()
{
var candidates = CandidatesExcelImporter.LoadCandidates( @"X:\candidats.xlsx" );
var tweets = TweetsImporter.LoadTweets( candidates.Select( c => c.TwitterHandle ) );
File.WriteAllText( "candidates.json", DjangoContainer.Wrap( "candidate", candidates ) );
File.WriteAllText( "tweets.json", DjangoContainer.Wrap( "tweet", tweets ) );
}
private static void Process()
{
string candidatesJson = File.ReadAllText( "candidates.json" );
string tweetsJson = File.ReadAllText( "tweets.json" );
var candidates = DjangoContainer.Unwrap<PoliticalCandidate>( candidatesJson );
var tweets = DjangoContainer.Unwrap<PoliticalTweet>( tweetsJson );
var mapping = new Dictionary<string, string>
{
{ "PS", "PS" },
{ "Les Verts", "Les Verts" },
{ "PLR", "PLR" },
{ "Jeunes PLR", "PLR" },
{ "Jeunes Verts", "Les Verts" },
{ "UDC", "UDC" },
{ "Jeunes UDC", "UDC" },
{ "JUSO", "PS" },
{ "PBD", "PBD" },
{ "Jeunes PBD", "PBD" },
{ "PDC", "PDC" },
{ "Jeunes PDC", "PDC" },
{ "Vert'libéraux", "Vert'libéraux" },
{ "POP et solidaritéS", null },
{ "Pirate", null },
{ "Vote blanc", null },
{ "Ecopop", null },
{ "PEV", null },
{ "Ensemble à Gauche", null },
{ "MCG", null },
{ "Jeunes MCG", null },
{ "JDC", "PDC" },
{ "CS-POP", null },
{ "PCSI", null },
{ "La Gauche", null },
{ "POP", null },
{ "Centre Gauche-PCS", null }
};
candidates = candidates.Where( c => mapping.ContainsKey( c.PartyName ) && mapping[c.PartyName] != null );
foreach ( var cand in candidates )
{
cand.GroupedPartyName = mapping[cand.PartyName];
}
File.WriteAllText( "filtered_candidates.json", DjangoContainer.Wrap( "candidate", candidates ) );
}
}
}