def index(request):
    if request.method == 'POST' and 'csvFile' in request.FILES:
        csv = request.FILES['csvFile']
        csv_file_name = str(request.FILES['csvFile'])
        parsed_csv = parse_csv(csv)
        if parsed_csv == 'Not a CSV':
            return JsonResponse({"notCsv": "true"})
        header = parsed_csv.pop(0)
        response_data = create_response(parsed_csv, header, False)
        context = {"html": response_data['html'], "data": response_data["unique_mpn"]}
        return JsonResponse(context)
    elif len(request.POST.getlist('rawHTML')) != 0:
        html = request.POST.getlist("rawHTML")[0]
        parsed_html = parse_html(html)
        head = [value.get_text() for value in parsed_html['header']]
        table = get_html_text(parsed_html['rows'])
        if request.POST.getlist('sort')[0]  == "false":
            file_name = request.POST.getlist("filename")[0]
            for row in table[2:-1]:
                Build_Data.objects.create(file_name=file_name, designator=row[0], footprint=row[1], mid_x=row[2], mid_y=row[3], ref_x=row[4], ref_y=row[5], pad_y=row[6], pad_x=row[7], layer=row[8], rotation=row[9], comment=row[10])
            return HttpResponse("")
        else:       
            response_data = create_response(table, head, True)
            context = {"html": response_data['html'], "data": response_data["unique_mpn"]}
            return JsonResponse(context)
    return render(request, 'home.html')
Beispiel #2
0
def get_html_tutors(names, urls):
    html_dict = {}
    urls_dict = dict(zip(names, urls))
    for name, url in urls_dict.items():
        url = f'{url}tutors/?year=2020'
        html = get_html_text(url)
        if '/' in name: name = slash_handler(name)
        html_dict[name] = html
        print('.', end='')
        sleep(.2)
    return html_dict
Beispiel #3
0
 def make_answers_list(self):
     try:
         # with open(self.input_file, 'r') as input_file:
         input_str = self.input_file
         answers_div = BeautifulSoup(input_str).find("div", id="answers")
         answers_divs = BeautifulSoup(str(answers_div)).findAll("div", {"class": "answer"})
         answers = []
         if not answers_divs:
             raise ParseError("")
         for answer in answers_divs:
             ans_soap = BeautifulSoup(str(answer))
             votes_span = ans_soap.findAll("span", {"class": "vote-count-post "})[0]
             votes = get_html_text(votes_span)
             ans_div = ans_soap.findAll("div", {"class": "post-text"})[0]
             accepted_ans = ans_soap.findAll("span", {"class": "vote-accepted-on"})
             accepted = len(accepted_ans) > 0
             ans = get_html_text(ans_div)
             answer = {"text": ans, "html_text": ans_div, "votes": eval(votes), "accepted": accepted}
             answers.append(answer)
         return answers
     except Exception:
         raise ParseError("Couldn't parse file %s" % self.input_file)
Beispiel #4
0
	def get_question_vote(self, input_str):
		question_soup = self.get_question_soup(input_str)
		vote_span = question_soup.findAll("span", {"class":"vote-count-post"})[0]
		vote = get_html_text(vote_span)
		return vote
Beispiel #5
0
	def get_question_title(self, input_str):
		soup = BeautifulSoup(input_str)
		question_header_div = soup.find("div", id="question-header")
		name = get_html_text(question_header_div)
		return name
Beispiel #6
0
	def get_question_text(self, input_str):
		question_soup = self.get_question_soup(input_str)
		question_tr = question_soup.findAll("div", {'class': "post-text"})[0]
		text = get_html_text(question_tr)
		return text, question_tr