Legality of Cannabis by U.S. Jurisdiction

Content deleted Content added
Titoxd (talk | contribs)
upgrade to v1.01
Titoxd (talk | contribs)
major upgrade (v.2.00)
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
This is an [[extension (computing)|extension]] of [[User:Flcelloguy|Flcelloguy]]'s Tool, which processes the HTML from a contribs file and parses it into a file readable by the tool. It is not finished, but the core is done, so I'm publishing it as v1.00.
This is an [[extension (computing)|extension]] of [[User:Flcelloguy|Flcelloguy]]'s Tool, which processes the HTML from a contribs file and parses it into a file readable by the tool. It is not finished, but the core is done, so I'm publishing it as v1.00.


'''It won't run''', since the functions written by Flcelloguy are temporarily bypassed (visible at <tt>main2</tt>) to test the extension. All it does is parse the contributions. [[User:Titoxd|Tito]][[Wikipedia:Esperanza|<span style="color:#008000;">xd</span>]]<sup>([[User_talk:Titoxd|?!?]] - [[Wikipedia:Semi-protection policy|did you read this?]])</sup> 04:21, 8 December 2005 (UTC)
'''It won't run''', since the functions written by Flcelloguy (which actually count the contributions) are in a separate file (available at <tt>[[User:Flcelloguy/Tool]]</tt>). All it does is parse the contributions. [[User:Titoxd|Tito]][[Wikipedia:Esperanza|<span style="color:#008000;">xd</span>]]<sup>([[User_talk:Titoxd|?!?]] - [[Wikipedia:Semi-protection policy|did you read this?]])</sup> 04:21, 8 December 2005 (UTC)


== Revisions ==
== Revisions ==
*v1.00: Original version, parses contribs to HTML file
*'''''[http://en.wikipedia.org/w/index.php?title=User:Titoxd/Flcelloguy%27s_Tool&oldid=30556816 v1.00]''''': Original version, parses contribs to HTML file
*v1.01: Revision, split into a separate class, removed print command to system buffer (slowing down tool, only used for debugging)
*'''''[http://en.wikipedia.org/w/index.php?title=User:Titoxd/Flcelloguy%27s_Tool&diff=next&oldid=30556816 v1.01]''''': Revision, split into a separate class, removed print command to system buffer (slowing down tool, only used for debugging)
*'''''v2.00''''': begun processing the raw HTML file, parsed date/time stamp and page name into a special "<tt>Contrib</tt>" class. Minor edits, edit summaries and most recent edits still to be implemented.


== Code ==
== Code ==
=== PurgeContribs.java ===
<pre>
<pre>
<nowiki>/**
<nowiki>/**
Line 22: Line 24:
import java.io.FileWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.IOException;
import java.util.StringTokenizer;

import javax.swing.JOptionPane;
import javax.swing.JOptionPane;


Line 33: Line 37:
String outFile$ ="";
String outFile$ ="";
outFile$ = JOptionPane.showInputDialog("Output file:", outFile$);
outFile$ = JOptionPane.showInputDialog("Output file:", outFile$);
PurgeContribs(inFile$, outFile$);
Purge(inFile$, outFile$);
}
}


Line 42: Line 46:
* @throws IOException
* @throws IOException
*/
*/
public static void PurgeContribs(String contribsFile, String listFile) throws IOException
public static void Purge(String contribsFile, String listFile) throws IOException
{
{
FileReader reader = new FileReader(contribsFile);
FileReader reader = new FileReader(contribsFile);
Line 50: Line 54:
BufferedWriter out = new BufferedWriter(writer);
BufferedWriter out = new BufferedWriter(writer);
String inString ="";
String inString ="";
String outString ="";
boolean endContribs = false; //marks whether all the contributions have been parsed
boolean endContribs = false; //marks whether all the contributions have been parsed
Line 64: Line 69:
if ((inString.trim().compareTo("</ul>")!=0))
if ((inString.trim().compareTo("</ul>")!=0))
{
{
out.write(inString.trim(),0,inString.length());
//System.out.println(inString.trim());
//System.out.println(inString.trim());
outString = Parse(inString.trim()).pageName;
//System.out.println(outString.trim());
out.write(inString.trim(),0,inString.length());
}
}
else
else
Line 79: Line 87:
}
}


public static Contrib Parse(String purgedLine) throws IOException
{
/**** Take out the <li> tags ****/
String midString1;
String timeStamp;
boolean endLoop = false;
midString1 = purgedLine.substring(4,purgedLine.length()-5);
/**** Process the time stamp ****/
StringTokenizer token;
token = new StringTokenizer(midString1.trim());
String time = token.nextToken();
String day = token.nextToken();
String month = token.nextToken();
String year = token.nextToken();
timeStamp = time + " " + day + " " + month + " " + year;
/**** Process the page name ****/
String dummy = token.nextToken(); //get rid of (<a
String URL = token.nextToken();
String pageName = URL.substring(25,URL.length()-20);
/**** Get rid of a few extra tokens ****/
do
{
endLoop = false;
dummy = token.nextToken();
if (dummy.lastIndexOf('<') != -1)
{
if (dummy.substring(dummy.lastIndexOf('<'),dummy.lastIndexOf('<')+3).compareTo("</a>") != 0) endLoop = true;
}
}
while (endLoop==false);
/**** Do the same with the diff link ****/
dummy = token.nextToken(); //get rid of (<a
String dummyURL = token.nextToken(); //this URL is not needed, so it is dummied out
String dummyPageName = URL.substring(25,dummyURL.length()-20); //ditto
do
{
endLoop = false;
dummy = token.nextToken();
if (dummy.lastIndexOf('<') != -1)
{
if (dummy.substring(dummy.lastIndexOf('<'),dummy.lastIndexOf('<')+3).compareTo("</a>") != 0) endLoop = true;
}
}
while (endLoop==false);
Contrib contrib = new Contrib(timeStamp, pageName, false, null, false);
return contrib;
}
}</nowiki></pre>
=== Contrib.java ===
<pre>
<nowiki>/**
* Contribution class for Flcelloguy's Tool
* @see [[User:Flcelloguy/Tool]]
* @author Titoxd
* @version 1.00
* @docRoot: http://en.wikipedia.org/wiki/User:Titoxd/Flcelloguy's_Tool
* @copyright: Permission is granted to distribute freely, provided attribution is granted.
*/

public class Contrib
{

public Contrib(String inStamp, String inName, boolean inMin, String inSummary, boolean inTop)
{
timeStamp = inStamp;
pageName = inName;
minorEdit = inMin;
editSummary= inSummary;
topEdit = inTop;
}
public String timeStamp;
public String pageName;
public boolean minorEdit;
public String editSummary;
public boolean topEdit;
public String toString()
{
String returnString = "Time: " + timeStamp + "\r" +
"Page: " + pageName + "\r" +
"Minor edit: " + minorEdit + "\r" +
"Edit Summary: " + editSummary + "\r" +
"Most recent edit: " + topEdit;
return returnString;
}
}</nowiki></pre>
}</nowiki></pre>

Revision as of 07:36, 8 December 2005

This is an extension of Flcelloguy's Tool, which processes the HTML from a contribs file and parses it into a file readable by the tool. It is not finished, but the core is done, so I'm publishing it as v1.00.

It won't run, since the functions written by Flcelloguy (which actually count the contributions) are in a separate file (available at User:Flcelloguy/Tool). All it does is parse the contributions. Titoxd(?!? - did you read this?) 04:21, 8 December 2005 (UTC)[reply]

Revisions

  • v1.00: Original version, parses contribs to HTML file
  • v1.01: Revision, split into a separate class, removed print command to system buffer (slowing down tool, only used for debugging)
  • v2.00: begun processing the raw HTML file, parsed date/time stamp and page name into a special "Contrib" class. Minor edits, edit summaries and most recent edits still to be implemented.

Code

PurgeContribs.java

/**
 * HTML -> ContribFile converter for Flcelloguy's Tool
 * @see [[User:Flcelloguy/Tool]]
 * @author Titoxd
 * @version 1.00
 * @docRoot: http://en.wikipedia.org/wiki/User:Titoxd/Flcelloguy's_Tool
 * @copyright: Permission is granted to distribute freely, provided attribution is granted.
 */
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.StringTokenizer;

import javax.swing.JOptionPane;

public class PurgeContribs
{
	public static void main (String args[]) throws IOException
	{
		
		String inFile$= "";
		inFile$ = JOptionPane.showInputDialog("Input file:", inFile$);
		String outFile$ ="";
		outFile$ = JOptionPane.showInputDialog("Output file:", outFile$);
		Purge(inFile$, outFile$);
	}


	/** 
	 * @param contribsFile (input file in raw HTML)
	 * @param listFile (output file, for the moment in raw HTML, will be modified later to process contribs easier)
	 * @throws IOException 
	 */
		public static void Purge(String contribsFile, String listFile) throws IOException
		{
			FileReader reader = new FileReader(contribsFile);
			BufferedReader in = new BufferedReader(reader);
			
			FileWriter writer = new FileWriter(listFile);
			BufferedWriter out = new BufferedWriter(writer);
			
			String inString ="";
			String outString ="";
			boolean endContribs = false;		//marks whether all the contributions have been parsed
			
			inString = in.readLine();	//read from file and discard
			
			do
			{
				if ((inString.trim().compareTo("<ul>")==0) && (endContribs == false)) 	//until the <ul> tag is reached,
				{
					do
					{
						inString = in.readLine();	//then start reading and recording
						if ((inString.trim().compareTo("</ul>")!=0))
						{
							//System.out.println(inString.trim());
							outString = Parse(inString.trim()).pageName;
							//System.out.println(outString.trim());
							
							out.write(inString.trim(),0,inString.length());
						}
						else
						{
							endContribs = true;
						}
					} while (endContribs != true);
				}
				inString = in.readLine();	//read from file and discard
			} while (inString != null);
			in.close();
			out.close();
		}

		public static Contrib Parse(String purgedLine) throws IOException
		{
			/**** Take out the <li> tags ****/
			String midString1;
			String timeStamp;
			boolean endLoop = false; 
			midString1 = purgedLine.substring(4,purgedLine.length()-5);
			
			/**** Process the time stamp ****/
			StringTokenizer token;
			token = new StringTokenizer(midString1.trim());
			String time = token.nextToken();
			String day = token.nextToken();
			String month = token.nextToken();
			String year = token.nextToken(); 
				
			timeStamp = time + " " + day + " " + month + " " + year; 
			
			/**** Process the page name ****/
			
			String dummy = token.nextToken();  //get rid of (<a
			String URL = token.nextToken();
			String pageName = URL.substring(25,URL.length()-20);
			
			/**** Get rid of a few extra tokens ****/
			
			do
			{
				endLoop = false;
				dummy = token.nextToken();
				if (dummy.lastIndexOf('<') != -1)
				{
					if (dummy.substring(dummy.lastIndexOf('<'),dummy.lastIndexOf('<')+3).compareTo("</a>") != 0) endLoop = true;
				}
			}
			while (endLoop==false);
			
			/**** Do the same with the diff link ****/
			dummy = token.nextToken();  //get rid of (<a
			String dummyURL = token.nextToken(); 	//this URL is not needed, so it is dummied out
			String dummyPageName = URL.substring(25,dummyURL.length()-20); 	//ditto
			do
			{
				endLoop = false;
				dummy = token.nextToken();
				if (dummy.lastIndexOf('<') != -1)
				{
					if (dummy.substring(dummy.lastIndexOf('<'),dummy.lastIndexOf('<')+3).compareTo("</a>") != 0) endLoop = true;
				}
			}
			while (endLoop==false);
			
			Contrib contrib = new Contrib(timeStamp, pageName, false, null, false);
			return contrib;
	}
		
		
}

Contrib.java

/**
 * Contribution class for Flcelloguy's Tool
 * @see [[User:Flcelloguy/Tool]]
 * @author Titoxd
 * @version 1.00
 * @docRoot: http://en.wikipedia.org/wiki/User:Titoxd/Flcelloguy's_Tool
 * @copyright: Permission is granted to distribute freely, provided attribution is granted.
 */

public class Contrib
{

	public Contrib(String inStamp, String inName, boolean inMin, String inSummary, boolean inTop)
	{
		timeStamp = inStamp;
		pageName = inName;
		minorEdit = inMin;
		editSummary= inSummary;
		topEdit = inTop;
		
	}
	public String timeStamp;
	public String pageName;
	public boolean minorEdit;
	public String editSummary;
	public boolean topEdit;
	
	public String toString()
	{
		String returnString = "Time: " + timeStamp + "\r" + 
			"Page: " + pageName + "\r" + 
			"Minor edit: " + minorEdit + "\r" + 
			"Edit Summary: " + editSummary + "\r" +
			"Most recent edit: " + topEdit;
		return returnString;
	}
}