Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
balayette committed Nov 27, 2017
1 parent c3002b7 commit 2460181
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 6 deletions.
47 changes: 45 additions & 2 deletions PwnVoltaire/Api.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.IO;
using System;
using System.IO;
using System.Net;
using System.Text;
using Newtonsoft;


namespace PwnVoltaire
{
Expand All @@ -10,11 +13,14 @@ public class Api

public Api()
{
this._apiString = "http://syn-web01.synapse-fr.com/api/textchecker/correct_logged";
//this._apiString = "http://syn-web01.synapse-fr.com/api/textchecker/correct_logged";
// this._apiString = "http://orthographe.reverso.net/RISpellerWS/RestSpeller.svc/v1/CheckSpellingAsXml/language=fra?outputFormat=json&doReplacements=true&interfLang=fr&dictionary=both&spellOrigin=interactive&includeSpellCheckUnits=true&includeExtraInfo=true&isStandaloneSpeller=true";
this._apiString = "http://orthographe.reverso.net/RISpellerWS/RestSpeller.svc/v1/CheckSpellingAsXml/language=fra?outputFormat=json&doReplacements=true&interfLang=fra&dictionary=both&spellOrigin=interactive&includeSpellCheckUnits=true&includeExtraInfo=true&isStandaloneSpeller=true";
}

public string GetApiResp(string sentence)
{
/*
WebRequest wr = WebRequest.Create(this._apiString);
wr.Method = "POST";
wr.ContentType = "text/xml; charset=utf-8";
Expand All @@ -33,6 +39,43 @@ public string GetApiResp(string sentence)
resp.Close();
return r;
*/

HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(this._apiString);
wr.Method = "POST";
wr.Headers.Add("Origin", "http://www.reverso.net");
wr.Referer = "http://www.reverso.net/orthographe/correcteur-francais/";
wr.Host = "orthographe.reverso.net";
wr.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36";
wr.Headers.Add("Username", "OnlineSpellerWS");
wr.Headers.Add("Created", "01/01/0001 00:00:00");
wr.Accept = "*/*";
wr.Headers.Add("Access-Control-Request-Method", "POST");
wr.Headers.Add("Access-Control-Request-Headers", "accept, content-type, created, username, x-requested-with");
wr.Headers.Add("Accept-Language", "fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4");
wr.Headers.Add("Accept-Encoding:gzip, deflate, sdch");
foreach(var k in wr.Headers.AllKeys)
{
Console.WriteLine(k + " " + wr.Headers[k]);
}
var data = Encoding.UTF8.GetBytes(sentence);
Console.WriteLine(sentence);
var dataStream = wr.GetRequestStream();
dataStream.Write(data, 0, data.Length);
dataStream.Close();

var resp = wr.GetResponse().GetResponseStream();
var rdr = new StreamReader(resp);

var r = rdr.ReadToEnd();
resp.Close();

dynamic jsono = Newtonsoft.Json.JsonConvert.DeserializeObject(r);

Console.WriteLine("RAW API RESPONSE : \n\n" + r + "\n\n\n");
Console.WriteLine("Corrections : " + jsono.Corrections);

return jsono.Corrections;
}
}
}
4 changes: 2 additions & 2 deletions PwnVoltaire/Error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ private void _parseMessage(string msg)
{
this._message = msg.Replace("<message>", "")
.Replace("</message>", "")
.Replace("[b]", "")
.Replace("[/b]", "");
.Replace("#!", "")
.Replace("#$", "");
}

private void _parseError(string err)
Expand Down
4 changes: 4 additions & 0 deletions PwnVoltaire/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ private string GetSentence()

private void button1_Click(object sender, EventArgs e)
{

try
{
this.richTextBox1.Text = "";
var str = this.GetSentence();
Console.WriteLine("Found a sentence : " + str);
if (str == null)
return;
var errors = PwnVoltaire.GetReadableOutput(this._api.GetApiResp(str));
Expand All @@ -106,6 +108,8 @@ private void button1_Click(object sender, EventArgs e)
{
Console.WriteLine(e.ToString());
}
//var errs = PwnVoltaire.GetReadableOutput(this._api.GetApiResp("Je fai des faute"));

}


Expand Down
23 changes: 22 additions & 1 deletion PwnVoltaire/PwnVoltaire.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Web;
using System.Xml;

namespace PwnVoltaire
{
Expand All @@ -12,16 +13,36 @@ public static class PwnVoltaire

public static List<Error> GetReadableOutput(string s)
{

var xml = HttpUtility.HtmlDecode(s);

var ret = new List<Error>();
//var errors = Regex.Matches(xml, "<error nb=\" \">(.*?)</errors>")

/*
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
foreach(XmlElement sentence in doc.GetElementsByTagName("error"))
{
Console.WriteLine("Error : ");
Console.WriteLine(sentence.GetAttribute("type"));
}
*/


/*
// fuck XML
if (!xml.Contains("errors"))
return ret;

*/
Console.WriteLine("Contains errors");
var messages = Regex.Matches(xml, "<message>(.*?)</message>");
var errors = Regex.Matches(xml, "<error (.*?)>");
for (int i = 0; i < messages.Count; i++)
{
Console.WriteLine(messages[i].Value);
Console.WriteLine(errors[i].Value);
ret.Add(new Error(messages[i].Value, errors[i].Value));
}
return ret;
Expand Down
6 changes: 5 additions & 1 deletion PwnVoltaire/PwnVoltaire.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{3FD92718-9568-4199-B3D2-6F38156B1B5D}</ProjectGuid>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<RootNamespace>PwnVoltaire</RootNamespace>
<AssemblyName>PwnVoltaire</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
Expand Down Expand Up @@ -35,6 +35,9 @@
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
Expand Down Expand Up @@ -80,6 +83,7 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down

0 comments on commit 2460181

Please sign in to comment.