Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Done... ish #10

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# project_what_have_you_done
Build an application to help track the legislative activities of your local representatives.

Luke E Summerscales
Binary file not shown.
38 changes: 38 additions & 0 deletions css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions css/style.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions css/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
*,
*:after,
*:before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}

body {
margin-top: 100px;
}
.container {
width: 100%;
}
.content {
width: 75%;
margin: auto;
}
.main {
text-align: center;
width: 50%;
margin: auto;
}
.black-on-yellow {
background-color: yellow;
font-variant: small-caps;
color: black;
}
.numput {
text-align: center;
width: 30px;
height: 40px;
font-size: 18px;
font-weight: bold;
}
.req{
color: red;
}
43 changes: 43 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="css/style.css" rel="stylesheet" type="text/css"/>
<title>What have you done</title>
</head>
<body>
<div class="container">
<div class="content">
<header class="main">
<h1 class="black-on-yellow">What Have You Done?</h1>
</header>
<section class="main">
<h2>
Discover the <strong>voting records</strong><br />
of your <storng>local representatives</storng>
</h2>
<p>
Then pester their offices until their views reflect yours
</p>
</section>
<section class="main">
<h2>Enter Your <strong>Zip</strong> Code</h2>
<form action="/listings" method="post">
<div>
<input name="a" class="numput" type="text" maxlength="1" required />
<input name="b" class="numput" type="text" maxlength="1" required />
<input name="c" class="numput" type="text" maxlength="1" required />
<input name="d" class="numput" type="text" maxlength="1" required />
<input name="e" class="numput" type="text" maxlength="1" required />
</div>
<div>
<input type="submit" value="Go" onclick="checkReq()" />
</div>
</form>
</section>
</div>
</div>
<script src="js/check.js"></script>
</body>
</html>
22 changes: 22 additions & 0 deletions js/check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var input = document
.getElementsByClassName("numput");


function checkReq() {
for(var i = 0; i < input.length; i++){
if(input[i].value == "" || isNaN(input[i].value)) {
input[i].setAttribute("class", "numput req");
input[i].value = "";
} else {
input[i].setAttribute("class", "numput");
}
}
}
checkReq();

console.log("SCRIPT RUNNING");
for(var i = 0; i < input.length; i++){
input[i].addEventListener("keyup", function(){
checkReq();
});
}
131 changes: 131 additions & 0 deletions js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
request = require("request");
http = require("http");
fs = require("fs");
qs = require("querystring");
Promise = require("promise");

var zip = "";
var legislators = [];
var house = "<h2>House</h2><p>";
var senate = "<h2>Senate</h2><p>";
var total = "";

function parse(data) {
var data = JSON.parse(data).results;
data.forEach(function(item){
var temp = [
item["first_name"],
item["last_name"],
item["chamber"]
]
legislators.push(temp);
});
for(var i = 0; i < legislators.length; i++) {
if(legislators[i][2] == "house") {
house += legislators[i][0] + " ";
house += legislators[i][1] + "<br />";
} else {
senate += legislators[i][0] + " ";
senate += legislators[i][1] + "<br />";
}
}
house += "</p>";
senate += "</p>";
total += house;
total += senate;
console.log("done");
return total;
}

function byZip(error, response, body){
if(!error && response.statusCode == 200) {
var result = parse(body);
return result;
} else {
console.log(error);
}
}

var server = http.createServer(function(req, response){
console.log("Incoming request...");
console.log(`Requesting ${req.url}`);
switch(req.url){
case "/css/style.css":
fs.readFile("css/style.css", "utf8", function(err, data){
response.writeHead(200, {"Content-Type":"text/css"});
response.write(data);
response.end();
console.log("Success")
});
break;
case "/css/style.css.map":
fs.readFile("css/style.css.map", "utf8", function(err, data){
response.writeHead(200, {"Content-Type":"text/css"});
response.write(data);
response.end();
console.log("Success")
});
break;
case "/js/check.js":
fs.readFile("js/check.js", "utf8", function(err, data){
response.writeHead(200, {"Content-Type" : "application/javascript"});
response.write(data);
response.end();
console.log("Success");
});
break;
case "/":
fs.readFile("index.html", "utf8", function(err, data){
response.writeHead(200, {"Content-Type" : "text/html"});
response.write(data);
console.log("Success");
response.end();
});
break;
case "/listings":
zip = "";
if(req.method == "POST"){
req.on("data", function(data){
zip += data;
zip = qs.parse(zip);
zip = zip["a"] + zip["b"] + zip["c"] + zip["d"] + zip["e"];
console.log("Gathering data for ZIP code", zip);
options["url"] = `https://congress.api.sunlightfoundation.com/legislators/locate?zip=${zip}`;
var promise = new Promise(function(res, rej){
request(options, function(err, resu, body){
res(byZip(err, resu, body));
});
console.log("Reqeust Promise")
});
promise.then(function(msg){
console.log("Then Promise")
fs.readFile("listings.html", "utf8", function(err, data){
response.writeHead(200, {"Content-Type" : "text/html"});
data = data.replace(/{{ZIP}}/, zip);
data = data.replace(/{{CONTENT}}/, msg);
response.write(data);
console.log("Success");
response.end();
});
});
});
}
break;
}
console.log("Responding");
});

var options = {
url: "",
headers: {
"user-agent": "req"
}
};
var url = {
host: "localhost",
port: "5000",
}

server.listen(url, function(){
console.log(`Server listening at ${url["host"]}:${url["port"]}`);
});
21 changes: 21 additions & 0 deletions listings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!doctype html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta charset="utf-8" />
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="container">
<div class="content">
<header class="main">
<h1 class="black-on-yellow">What Have You Done?</h1>
</header>
<section class="main">
<h2>{{ZIP}}</h2>
{{CONTENT}}
</section>
</div>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions node_modules/.bin/sshpk-conv

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/sshpk-sign

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/sshpk-verify

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/uuid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions node_modules/ajv/.tonic_example.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions node_modules/ajv/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading