Archived

This topic is now archived and is closed to further replies.

DarkZe

[Uservoice] automate the votes

9 posts in this topic

Hi there.

 

I recently bought a new mobile phone with Windows Phone 8 and I discovered it cannot share Internet connexion through USB (tethering).

Microsoft actively checks the website windowsphone.uservoice.com to discuss with the users asking new features.

 

I wrote this script to powerlevel a little bit the vote for this feature :P

It obviously can be adapted for other votes on Uservoice.

Be careful: the website blocks after x votes with the same IP address. Don't be surprise you cannot post more than 20 votes at a time.

using System;using System.IO;using System.Net;using System.Text;using System.Text.RegularExpressions;using System.Threading;namespace Uservoice{    class Program    {        // ###############################        // #          Settings           #        // ###############################        // Url corresponding to the public page for voting        private const string UrlOfTheVote = "http://windowsphone.uservoice.com/forums/101801-feature-suggestions/suggestions/3581775-usb-tethering";        // Url used by Uservoice to increase the number of vote (just substitute the numbers from the previous url)        private const string UrlOfTheAjaxRequest = "http://windowsphone.uservoice.com/api/v1/forums/101801/suggestions/3581775/votes.json";        // Url for managing sessions        private const string UrlOfTheSessions = "http://windowsphone.uservoice.com/session";        // The number of the suggestion (first number in the url above)        private const int SuggestionNumber = 101801;        // Time between vote        private static readonly TimeSpan _timeBetweenVote = TimeSpan.FromSeconds(30);        /// <summary>        /// The entry-point with an infinite loop.        /// </summary>        /// <remarks>Written by DarkZe.</remarks>        static void Main()        {            uint counter = 0;            while (true)            {                counter++;                Console.Write("Vote #{0} in progress... ", counter);                Vote();                Console.WriteLine("done");                Thread.Sleep(_timeBetweenVote);            }        }        /// <summary>        /// Automates votes on Uservoice.com.        /// </summary>        /// <remarks>Written by DarkZe.</remarks>        private static void Vote()        {            // ###############################            // #     Get the identifiers     #            // ###############################            var cookies = new CookieContainer();            var request = (HttpWebRequest)WebRequest.Create(UrlOfTheVote);            request.CookieContainer = cookies;            string csrfToken;            using (var response = request.GetResponse())            {                var regex = new Regex("<meta name=\"csrf-token\" content=\"(.*)\"/>");                csrfToken = regex.Match((new StreamReader(response.GetResponseStream())).ReadToEnd()).Groups[1].Value;            }            // ###############################            // #  Authenticate the session   #            // ###############################            request = (HttpWebRequest)WebRequest.Create(UrlOfTheSessions);            request.CookieContainer = cookies;            var random = new Random();            var data = string.Format("site2=1&forum_id={0}&display_name=str{1}&email={1}%40hotmail.com", SuggestionNumber, random.Next(100000, 999999));            var encodedData = Encoding.UTF8.GetBytes(data);            request.Method = "POST";            request.ContentLength = encodedData.Length;            request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";            request.Headers.Add("X-CSRF-Token", csrfToken);            using (var stream = request.GetRequestStream())            {                stream.Write(encodedData, 0, encodedData.Length);            }            request.GetResponse().Dispose();            // ###############################            // #       Submit the vote       #            // ###############################            request = (HttpWebRequest)WebRequest.Create(UrlOfTheAjaxRequest);            request.CookieContainer = cookies;            data = "to=3&oauth_signature_method=HMAC-SHA1&oauth_consumer_key=1aEpNly5pjcYOpC7L4FXag";            encodedData = Encoding.UTF8.GetBytes(data);            request.Method = "POST";            request.ContentLength = encodedData.Length;            request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";            request.Headers.Add("X-CSRF-Token", csrfToken);            using (var stream = request.GetRequestStream())            {                stream.Write(encodedData, 0, encodedData.Length);            }            request.GetResponse().Dispose();        }    }}

Enjoy.

~ DarkZe

2 people like this

Share this post


Link to post
Share on other sites

Regex for html is stupid way for this task. Use should use string operations for that

Share this post


Link to post
Share on other sites

Nitpicky huh?

The search operation with regex takes less than 1ms in this case, so it's perfectly acceptable. Obviously, you are free to take and modify the code like you feel.

Share this post


Link to post
Share on other sites

Will make this multithreaded and tweak a bit tomorrow.

Looks like CMP github repo will be active again

Share this post


Link to post
Share on other sites

Votes are limited to 20 per IP. So unfortunately, multithreaded won't help you more, unless you planned to use some proxies.

Share this post


Link to post
Share on other sites

Votes are limited to 20 per IP. So unfortunately, multithreaded won't help you more, unless you planned to use some proxies.

Added proxy support to this :D

Will publish soon

UPD

I need your permesion to pusblish with CC license, so you should grant me it :D.

Share this post


Link to post
Share on other sites

As a newbie at programming I found this interesting and instructive :)

 

Thanks

Share this post


Link to post
Share on other sites

As a newbie at programming I found this interesting and instructive :)

 

Thanks

Please login or register to see this link.

СHECK THIS

Share this post


Link to post
Share on other sites

Added proxy support to this :D

Will publish soon

UPD

I need your permesion to pusblish with CC license, so you should grant me it :D.

If you quote my name in the project, I give you my permission. ;)

Edit: You can quote me like this: DarkZe@CodeMplosion

Share this post


Link to post
Share on other sites