Skip to content

Commit b9738b4

Browse files
Codeforces
0 parents  commit b9738b4

16 files changed

+1073
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
npm-debug.log
3+
node_modules

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.1.0 - First Release
2+
* Every feature added
3+
* Every bug fixed

LICENSE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2020 <Your name here>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# codeblue package
2+
3+
A short description of your package.
4+
5+
![A screenshot of your package](https://f.cloud.github.com/assets/69169/2290250/c35d867a-a017-11e3-86be-cd7c5bf3ff9b.gif)

keymaps/codeblue.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"atom-workspace": {
3+
"ctrl-alt-k": "codeblue:toggle"
4+
}
5+
}

lib/codeblue-view.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use babel';
2+
3+
import React from 'react';
4+
import ReactDOM from 'react-dom';
5+
import Root from './view/index'
6+
7+
export default class CodeblueView {
8+
9+
constructor(serializedState) {
10+
// Create root element
11+
this.element = document.createElement('div');
12+
13+
this.element.classList.add('codeblue');
14+
15+
ReactDOM.render(<div> <Root/></div>, this.element);
16+
}
17+
18+
serialize() {}
19+
20+
destroy() {
21+
this.element.remove();
22+
}
23+
24+
getElement() {
25+
return this.element;
26+
}
27+
28+
getTitle() {
29+
return 'CodeForces';
30+
}
31+
32+
getURI() {
33+
return 'atom://codeblue';
34+
}
35+
36+
getDefaultLocation() {
37+
return 'right';
38+
}
39+
40+
getAllowedLocations() {
41+
return ['left', 'right'];
42+
}
43+
44+
}

lib/codeblue.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use babel';
2+
3+
import CodeblueView from './codeblue-view';
4+
import {
5+
CompositeDisposable,
6+
Disposable
7+
} from 'atom';
8+
9+
export default {
10+
11+
subscriptions: null,
12+
13+
activate(state) {
14+
this.subscriptions = new CompositeDisposable(
15+
atom.workspace.addOpener(uri => {
16+
if (uri === 'atom://codeblue')
17+
return new CodeblueView();
18+
}),
19+
20+
atom.commands.add('atom-workspace', {
21+
'codeblue:toggle': () => this.toggle()
22+
}),
23+
24+
new Disposable(() => {
25+
atom.workspace.getPaneItems().forEach(item => {
26+
if (item instanceof CodeblueView) {
27+
item.destroy();
28+
}
29+
})
30+
})
31+
);
32+
},
33+
34+
deactivate() {
35+
this.subscriptions.dispose();
36+
},
37+
38+
toggle() {
39+
atom.workspace.toggle('atom://codeblue');
40+
}
41+
};

lib/view/index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use babel';
2+
3+
import React from 'react';
4+
import Problems from './problems';
5+
6+
export default class Root extends React.PureComponent {
7+
constructor(props){
8+
super(props);
9+
this.state = { num: 663, div: 2, id: 0 };
10+
}
11+
12+
display(){
13+
var editor = atom.workspace.getActiveTextEditor();
14+
if(editor){
15+
console.log(editor);
16+
}
17+
}
18+
19+
fetch(){
20+
21+
}
22+
23+
render() {
24+
return (
25+
<div>
26+
<h2>Codeforces Round #{this.state.num} (Div. {this.state.div})</h2>
27+
{this.state.id ? <input type="text"/> : <Problems contest={this.state}/> }
28+
<button onClick={()=> this.fetch()}>Submit</button>
29+
</div>
30+
);
31+
}
32+
}
33+
34+
// <button onClick={()=> this.toggler()}>Click me</button>

lib/view/problem.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use babel';
2+
3+
import React from 'react';
4+
5+
const Problem = ({prob})=>{
6+
if(prob.con==0){
7+
currentstate = <div className="accepted">Accepted</div>
8+
}else if (prob.con==1) {
9+
currentstate = <div className="wrong">Wrong on {prob.test}</div>
10+
}else if(prob.con==2){
11+
currentstate = <div className="tle">TLE on {prob.test}</div>
12+
}else if(prob.con==3){
13+
currentstate = <div className="queue"></div>
14+
}else{
15+
currentstate = <div></div>
16+
}
17+
return (
18+
<div className="prob">
19+
<span>{prob.alpha} - {prob.name}</span>
20+
<span className="totsub">{prob.sub}</span>
21+
{currentstate}
22+
</div>
23+
)
24+
}
25+
26+
export default Problem;

lib/view/problems.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
'use babel';
2+
3+
import React from 'react'
4+
import Problem from './problem'
5+
import request from 'request'
6+
import cheerio from 'cheerio'
7+
8+
export default class Problems extends React.PureComponent {
9+
constructor(props){
10+
super(props);
11+
this.state = {
12+
count: 0,
13+
probs: []
14+
};
15+
}
16+
17+
fetch(url){
18+
return new Promise((resolve, reject) => {
19+
request(url, (error, response, body) => {
20+
if (!error && response.statusCode == 200) {
21+
resolve(body)
22+
} else {
23+
reject({
24+
reason: 'Unable to download page'
25+
})
26+
}
27+
})
28+
})
29+
}
30+
31+
scrape(html){
32+
$ = cheerio.load(html)
33+
var i = 2
34+
var probs = []
35+
while(true){
36+
var al = $(`#pageContent > div.datatable > div:nth-child(6) > table > tbody > tr:nth-child(${i}) > td.id > a`).text().trim()
37+
if(al.length==0){
38+
break;
39+
}else{
40+
var nm = $(`#pageContent > div.datatable > div:nth-child(6) > table > tbody > tr:nth-child(${i}) > td:nth-child(2) > div > div:nth-child(1) > a`).text().trim()
41+
var sub = $(`#pageContent > div.datatable > div:nth-child(6) > table > tbody > tr:nth-child(${i}) > td > a`).text().trim().substring(2)
42+
probs.push({alpha: al, name: nm, con: -1, test: 1, sub: sub});
43+
}
44+
i++;
45+
}
46+
this.setState({probs: probs})
47+
}
48+
49+
componentWillMount(){
50+
var url = "https://codeforces.com/contest/"+this.props.contest.id
51+
this.fetch(url).then((html) => {
52+
this.scrape(html);
53+
}).catch((error) => {
54+
atom.notifications.addWarning(error.reason)
55+
})
56+
}
57+
58+
render(){
59+
return (
60+
<div className="problems">
61+
{this.state.probs && this.state.probs.map(prob=>{
62+
return (<Problem prob={prob}/>)
63+
})
64+
}
65+
</div>
66+
)}
67+
}
68+
69+
// [
70+
// {alpha: "A", name: "Suborrays"},
71+
// {alpha: "B", name: "Fix you"},
72+
// {alpha: "C", name: "Cyclic Permutations"},
73+
// {alpha: "D", name: "505"},
74+
// {alpha: "E", name: "Pairs of Pairs"}
75+
// ]

0 commit comments

Comments
 (0)