def setUp(self): self.ctl = Controller() self.ctl.load_accounts_json( os.path.join(os.getcwd(), 'accounts_sample.json'))
class Test(unittest.TestCase): def setUp(self): self.ctl = Controller() self.ctl.load_accounts_json( os.path.join(os.getcwd(), 'accounts_sample.json')) def test_submit(self): pass # self.crawler_hdu() # self.crawler_poj() # self.crawler_cf() def test_crawler_hdu(self): pid = 1000 lang = 'g++' ac_src = ''' #include<bits/stdc++.h> using namespace std; int main() { int a,b; while(cin>>a>>b)cout<<a+b<<endl; return 0; } ''' wa_src = ''' #include<bits/stdc++.h> using namespace std; int main() { int a,b; while(cin>>a>>b)cout<<a-b<<endl; return 0; } ''' self.ctl.add_task('hdu', ac_src, lang, pid) self.ctl.add_task('hdu', wa_src, lang, pid) import time time.sleep(5) def test_crawler_poj(self): pid = 1000 lang = 'g++' wa_src = ''' #include<iostream> using namespace std; int main() { int a,b; while(cin>>a>>b)cout<<a-b<<endl; return 0; } ''' ac_src = ''' #include<iostream> using namespace std; int main() { int a,b; while(cin>>a>>b)cout<<a+b<<endl; return 0; } ''' self.ctl.add_task('poj', ac_src, lang, pid) self.ctl.add_task('poj', wa_src, lang, pid) import time time.sleep(20) def test_crawler_cf(self): pid = '1A' lang = 'GNU G++11 5.1.0' src = ''' #include <iostream> using namespace std; int n,m,a; long long x,y; int main() { cin>>n>>m>>a; x=n/a+(n%a==0?0:1); y=m/a+(m%a==0?0:1);//sadjiowdqwdw cout<<x*y<<endl; return 0; //f**k you you } ''' self.ctl.add_task('codeforces', src, lang, pid) import time time.sleep(20)
from ojcrawler.control import Controller if __name__ == '__main__': x = Controller() print(x.get_problem('poj', '1001'))
from problem.models import * from django.db.models import Q from rest_framework import serializers import random from ojcrawler.control import Controller from rest_framework.decorators import action controller = Controller() class UpdateProblemSerializer(serializers.ModelSerializer): class Meta: model = Problem fields = '__all__' read_only_fields = ('accepted_number', 'submitted_number', 'difficult_number', 'origin_link', 'content') oj = models.CharField() pid = models.CharField() def validate_oj(self, value): value = value.lower() if value not in controller.supports(): raise serializers.ValidationError('Auto import only support oj_name in {}'.format(controller.supports())) return value def update(self, instance, validated_data): return instance def create(self, validated_data): instance = None
def test_something(self): controller = Controller() results = controller.get_contest('codeforces', 1221) self.assertEqual( results, ['x5281', 'x3781', 'x4455', 'x1309', 'x112', 'x78', 'x9'], results)
from ojcrawler.control import Controller if __name__ == '__main__': x = Controller() print(x.get_problem('hdu', '4114'))
class CrawlerController: controller = Controller() @staticmethod def get_controller(): return CrawlerController.controller