-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProfileParser.cs
171 lines (125 loc) · 5.61 KB
/
ProfileParser.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#define LOGINRUN
#define M_PROFILES
using System;
using System.Collections.Generic;
using System.Text;
using HtmlParsingLibrary;
using System.IO;
using System.ComponentModel;
//using System.Xml;
using System.Threading;
//using System.Data.SqlClient;
using System.Security.Cryptography;
using HttpLibrary;
//using System.Net;
using System.Diagnostics;
using System.Configuration;
using System.Globalization;
namespace Jeevansathi
{
partial class Program
{
static void Main(string[] args)
{
// Come till here for contact details
//<div class="lf"><img src="http://ser4.jeevansathi.com/img_revamp/cont_top_bg.gif"></div>
//<ul class="con_list">
// then pickup each field
//<li>Mobile no.</li>
//<li>Landline no.</li>
//<li>Suitable time to call</li>
//<li>Address</li>
//<li>Parent's address</li>
//<li>Messenger ID</li>
//</ul>
//<li>Mobile no. of Parent (Sibling)<br>
//<b>9938592881</b></li>
//<li>Suitable time to call<br>
//<b>1 AM to 1 AM</b></li>
//<li>Parent's address<br>
//<b>plot no 82 , nageshwar tangi , HB colony bhubaneswar orissa</b></li>
//<li>email ID<br>
//<b>[email protected]</b>
//</li>
//<li>Messenger ID<br>
//<b>farha_s_patnaik@Yahoo</b></li>
// Specify the directory you want to manipulate.
string profilesDir = @"D:\JS\";
string searchPattern = "*.htm";
DirectoryInfo di = new DirectoryInfo(profilesDir);
DirectoryInfo[] directories =
di.GetDirectories("*", SearchOption.TopDirectoryOnly);
FileInfo[] files =
di.GetFiles(searchPattern, SearchOption.AllDirectories);
Console.WriteLine(
"All sub-directories in {0}", profilesDir);
foreach (DirectoryInfo dir in directories)
{
Console.WriteLine(
"{0,-25} {1,25}", dir.FullName, dir.LastWriteTime);
}
Console.WriteLine();
Console.WriteLine("Files with pattern {0} in {0}", searchPattern, profilesDir);
//string strPreContacts = "<div class=\"lf\"><img src=\"http://ser4.jeevansathi.com/img_revamp/cont_top_bg.gif\"></div>";
string cdLocked = "Contact Details are Locked";
//string strPreContacts = "<ul class=\"con_list\"";
string strContactsStart = "<ul class=\"con_list\"";
//string strContactsStart = "<li>";
string strContactsEnd = "</ul>";
string fldStart = "<li>";
string fldEnd = "</li>";
string fldDataSep = "<br>";
string dataStart = "<b>";
string dataEnd = "</b>";
string noiseStr1 = "<br />";
string noiseStr2 = "<br/>";
foreach (FileInfo file in files)
{
Console.WriteLine(
"{0,-25} {1,25}", file.Name, file.LastWriteTime);
string profileId = file.Name.Remove(file.Name.IndexOf(".htm", 4));
// Read the htm file
string fileData = File.ReadAllText(file.FullName);
if (fileData.Contains(cdLocked))
{
Console.WriteLine("Details locked");
continue;
}
int idxContactsStart = 0;
//idxContactsStart = fileData.IndexOf(strPreContacts);
//idxContactsStart = fileData.IndexOf(">", idxContactsStart);
int tempIndex;
string contactsBlob = StringParser.GetStringBetween(fileData, idxContactsStart, strContactsStart, strContactsEnd, null, out tempIndex);
int nextDetailIdx = 0;
string token = StringParser.GetStringBetween(contactsBlob, 0, fldStart, fldEnd, null, out nextDetailIdx);
while (!String.IsNullOrEmpty(token))
{
// Field Name
string fldName = StringParser.GetStringBetween(token, 0, "", fldDataSep, null, out tempIndex);
Console.Write(fldName + ": ");
// Field's Data value
string dataValue = StringParser.GetStringBetween(token, 0, dataStart, dataEnd, null, out tempIndex);
// Noise removal
int noiseStrIdx = dataValue.IndexOf(noiseStr1);
if (noiseStrIdx > 0)
{
dataValue = dataValue.Remove(noiseStrIdx, noiseStr1.Length);
}
noiseStrIdx = dataValue.IndexOf(noiseStr2);
if (noiseStrIdx > 0)
{
dataValue = dataValue.Remove(noiseStrIdx, noiseStr2.Length);
}
Console.WriteLine(dataValue);
// Next token
token = StringParser.GetStringBetween(contactsBlob, nextDetailIdx, fldStart, fldEnd, null, out nextDetailIdx);
}
// <br>
// <li>Mobile no.</li>
// <b>[email protected]</b>
//Console.WriteLine(contactsBlob);
}
Console.ReadLine();
}
}
}