User:Angeliki/Prototyping 3

From XPUB & Lens-Based wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Catalogying

sorting.cgi

#!/usr/bin/env python3
import cgi
import cgitb; cgitb.enable()  #for seeing at errors in the code
import pandas as pd 
import csv
import sys, os, re, nltk, glob

print ("Content-type:text/html;charset=utf-")
print ()
output= "type here"
extract= ""

f = cgi.FieldStorage()
text = f.getvalue("text", "")

 
#read csv, and split on "," the line
csv_file = csv.reader(open('tfidf.csv', "r"), delimiter=",")
 
# Read the header, put all labels into a list
header = next(csv_file)
#print(header)
 
#loop through csv list
for row in csv_file :
    #if current rows 2nd value is equal to input, print that row
    if text == row[0]:
         scores = row
         #print(row)
 
# Zip the scores and the labels, remove the first item with the query
result = list(zip(header, scores))
del result[0]
# print(result)
 
# Sort the results
output = sorted(result, key=lambda tup: tup[1], reverse=True)

extract=[]
os.chdir("texts")
for file in glob.glob("*.txt"):
    # print(file)
    searchfile = open(file, "r")
    sents = nltk.sent_tokenize(searchfile.read())
    for sentence in sents:
        if re.search(r'\b({})\b'.format(text), sentence):
            extract.append(sentence)
    searchfile.close()

print ("""
<!DOCTYPE html>
<html>
<head>
	<title></title>
	<meta charset="utf-8">
</head>
<body>
<form method="get">
	<input type="submit" name="submit" value="search" >
    <textarea name="text"> {2} </textarea>
	<textarea name="result">  </textarea></br></br>
    {1}</br></br>
    {0}
</form>
</body>
</html>""".format(output, extract, text))
 
# i=0
# for i>=0:
#     print (output[i])
#     print (extract[i])
#     i++1

print (output[0])
print (extract[0])
print (output[1])
print (extract[1])

sorting.html

<!DOCTYPE html>
<html>
<head>
	<title></title>
	<meta charset="utf-8">
</head>
<body>
<form method="get" action="cgi-bin/sorting.cgi">
	<input type="submit" name="submit" value="search" >
	<textarea name="text"> Type here. </textarea>
	<textarea name="result"> extracts </textarea>
</form>
</body>
</html>

Sorting.png

Most downloaded books

import csv
from collections import defaultdict, Counter
data_list = []
with open('content.csv') as csvfile:
    data_list = list(csv.reader(x.replace('\0', '') for x in csvfile))
    for col in data_list:
        print(col[0])

id_counts = Counter()
country_counts = Counter()

with open('analyze.csv') as csvfile:
    reader = csv.reader(csvfile, delimiter='\t')
    booklist_br = []
    booklist_nl = []
    booklist_gr = []
    booklist_in = []
    booklist_ge = []
    booklist_au = []
    booklist_be = []
    booklist_hu = []
    booklist_ro = []

    for row in reader:
        if row[1] == 'Brazil':
            booklist_br.append((row[0],row[2]))

        if row[1] == 'Netherlands':
            booklist_nl.append((row[0],row[2]))

        if row[1] == 'Greece':
            booklist_gr.append((row[0],row[2]))

        if row[1] == 'Indonesia':
            booklist_in.append((row[0],row[2]))

        if row[1] == 'Germany':
            booklist_ge.append((row[0],row[2]))

        if row[1] == 'Austria':
            booklist_au.append((row[0],row[2]))

        if row[1] == 'Belgium':
            booklist_be.append((row[0],row[2]))

        if row[1] == 'Hungary':
            booklist_hu.append((row[0],row[2]))

        if row[1] == 'Romania':
            booklist_ro.append((row[0],row[2]))



    sorted_booklist_br = sorted(booklist_br, key=lambda x:int(x[1]), reverse=True)
    sorted_booklist_nl = sorted(booklist_nl, key=lambda x:int(x[1]), reverse=True)
    sorted_booklist_gr = sorted(booklist_gr, key=lambda x:int(x[1]), reverse=True)
    sorted_booklist_in = sorted(booklist_in, key=lambda x:int(x[1]), reverse=True)
    sorted_booklist_ge = sorted(booklist_ge, key=lambda x:int(x[1]), reverse=True)
    sorted_booklist_au = sorted(booklist_au, key=lambda x:int(x[1]), reverse=True)
    sorted_booklist_be = sorted(booklist_be, key=lambda x:int(x[1]), reverse=True)
    sorted_booklist_hu = sorted(booklist_hu, key=lambda x:int(x[1]), reverse=True)
    sorted_booklist_ro = sorted(booklist_ro, key=lambda x:int(x[1]), reverse=True)


    print('10 most downloaded books in Brazil:')
    for ide, downloads in sorted_booklist_br[:10]:
        print(downloads+"   "+data_list[int(ide)-1][1])
    print("-----------------------------")
    print('10 most downloaded books in the Netherlands:')
    for ide, downloads in sorted_booklist_nl[:10]:
        print(downloads+"   "+data_list[int(ide)-1][1])
    print("-----------------------------")
    print('10 most downloaded books in the Greece:')
    for ide, downloads in sorted_booklist_gr[:10]:
        print(downloads+"   "+data_list[int(ide)-1][1])
    print("-----------------------------")
    print('10 most downloaded books in the Indonesia:')
    for ide, downloads in sorted_booklist_in[:10]:
        print(downloads+"   "+data_list[int(ide)-1][1])
    print("-----------------------------")
    print('10 most downloaded books in the Germany:')
    for ide, downloads in sorted_booklist_ge[:10]:
        print(downloads+"   "+data_list[int(ide)-1][1])
    print("-----------------------------")
    print('10 most downloaded books in the Austria:')
    for ide, downloads in sorted_booklist_au[:10]:
        print(downloads+"   "+data_list[int(ide)-1][1])
    print("-----------------------------")
    print('10 most downloaded books in the Belgium:')
    for ide, downloads in sorted_booklist_be[:10]:
        print(downloads+"   "+data_list[int(ide)-1][1])
    print("-----------------------------")
    print('10 most downloaded books in the Hungary:')
    for ide, downloads in sorted_booklist_hu[:10]:
        print(downloads+"   "+data_list[int(ide)-1][1])
    print("-----------------------------")
    print('10 most downloaded books in the Romania:')
    for ide, downloads in sorted_booklist_ro[:10]:
        print(downloads+"   "+data_list[int(ide)-1][1])



10 most downloaded books in Brazil: 53 Quimica Organica 52 Introduction to Algorithms: A Creative Approach 48 English Grammar In Use with Answers: A Self-study Reference and Practice Book for Intermediate Students of English 3rd edition 46 Lições de Equações Diferenciais Ordinárias 44 Curso de Análise Vol. 1 44 International encyclopedia of the social sciences volume 11 40 Calculus 39 Física Matemática: Métodos Matemáticos para Engenharia e Física 39 Introduction to Quantum Mechanics 38 Calculus on Manifolds: A Modern Approach to Classical Theorems of Advanced Calculus


10 most downloaded books in the Netherlands: 229 Economics: Principles, Applications and Tools 114 The National Trust Manual of Housekeeping: The Care of Collections in Historic Houses Open to the Public 95 Het Diner 83 Business Process Change, Second Edition: A Guide for Business Managers and BPM and Six Sigma Professionals 66 The Scorch Trials (Maze Runner Trilogy, Book 2) 63 Models: A Comprehensive Guide to Attracting Women 60 The Maze Runner (Maze Runner Trilogy, Book 1) 54 Contemporary Political Philosophy: An Introduction (Second Edition) 51 De Aanslag 51 Vakliteratuur onder de loep: Een praktische handleiding om wetenschappelijke literatuur kritisch te beoordelen


10 most downloaded books in the Greece: 307 Ευρωπαϊκή Ιστορία 257 Οι αναρχικοί και οι εκλογές 177 Συνηθεις Διαφορικες Εξισωσεις 127 Βασικές Αρχές Κυτταρικής Βιολογίας, Τόμος I 108 Αντιλεξικόν ή Ονομαστικόν της Νεοελληνικής Γλώσσης 108 ΦΥΣΙΚΗ Ι ΜΗΧΑΝΙΚΗ 97 Συναρτήσεις Πολλών Μεταβλητών , 2η Εκδοση 92 Μαθήματα Στατιστικής 90 Μακιαβέλι 86 Ιστορία της Ευρώπης 1 - Από τη ρωμαϊκή αυτοκρατορία στα ευρωπαϊκά κράτη, 5ος-18ος αιώνας


10 most downloaded books in the Indonesia: 113 Research Design: Qualitative, Quantitative, and Mixed Methods Approaches (2nd Edition) 110 Object-Oriented Software Engineering Using UML, Patterns, and Java 109 Language Assessment - Principles and Classroom Practice 98 The SAGE Handbook of Qualitative Research 88 Learning UML 2.0 85 The Practice of English Language Teaching, 3rd Edition 83 Principles of Language Learning and Teaching (5th Edition) 79 Curriculum Development in Language Teaching (Cambridge Language Education) 75 Longman Complete Course for the Toefl Test: Preparation for the Computer and Paper Tests 72 How To Teach Speaking (HOW)


10 most downloaded books in the Germany: 168 Der Hundertjährige, der aus dem Fenster stieg und verschwand (Roman) 164 Sex Positions Illustrated: 101 Hot Positions You Can Do Right Now 161 Mathematik fur Ingenieure und Naturwissenschaftler - Klausur- und Ubungsaufgaben: 632 Aufgaben mit ausfuhrlichen Losungen zum Selbststudium und zur Prufungsvorbereitung, 4. Auflage 159 Das Lied von Eis und Feuer 1. Die Herren von Winterfell. 155 Fifty Shades of Grey 154 Der Herr der Ringe (Einbändige Ausgabe) 151 Chemie, 10 Auflage 148 Mathematische Formelsammlung: für Ingenieure und Naturwissenschaftler, 10. Auflage 146 Grundwissen Mathematikstudium - Analysis und Lineare Algebra mit Querverbindungen 144 Die Analphabetin, die rechnen konnte


10 most downloaded books in the Austria: 55 Chemie, 10 Auflage 54 Lösungen zur Aufgabensammlung Technische Mechanik 18. Auflage 41 Praktikum der Physik 39 Der Brenner und der liebe Gott 36 Fifty Shades of Grey 33 Supply Chain Management: Optimierung logistischer Prozesse 3. Auflage (Lehrbuch) 33 Grundzüge der Volkswirtschaftslehre: Eine Einführung in die Wissenschaft von Märkten 31 Sex Positions Illustrated: 101 Hot Positions You Can Do Right Now 30 Statistik ohne Angst vor Formeln: Das Studienbuch für Wirtschafts- und Sozialwissenschaftler. 2. Auflage 30 Physik: Lehr- und Übungsbuch, 3. Auflage


10 most downloaded books in Belgium (no French books!): 32 The Maze Runner (Maze Runner Trilogy, Book 1) 27 Fifty Shades of Grey 26 The Scorch Trials (Maze Runner Trilogy, Book 2) 25 Het Diner 22 Economics: Principles, Applications and Tools 22 The Death Cure 21 Verdwijn 20 Applied Longitudinal Analysis (Wiley Series in Probability and Statistics) 20 Technology brewing and malting 18 Building Construction Illustrated, 4th Edition


10 most downloaded books in Hungary: 48 The Digital Glocalization of Entertainment: New Paradigms in the 21st Century Global Mediascape 42 Fundamental University Physics: Quantum and Statistical Physics v.3 40 Contemporary Orthodontics 4th Edition 31 English Grammar In Use with Answers: A Self-study Reference and Practice Book for Intermediate Students of English 3rd edition 24 New Insights Into Business Toeic Workbook 21 The Scorch Trials (Maze Runner Trilogy, Book 2) 20 Extrusion Dies for Plastics and Rubber: Design and Engineering Computations 18 New Headway: Beginner Third Edition: Student's Book: Six-level general English course for adults (Headway ELT) 16 SPSS Survival Manual: A Step by Step Guide to Data Analysis Using the SPSS Program, 4th Edition 16 The English Studies Book


10 most downloaded books in Romania: 86 Set Sail! 3 - Vocabulary and Grammar Practice 79 Set Sail! 4 : Vocabulary and Grammar Practice 75 Set Sail! 3 : Pupil's Book 74 Set Sail!: Teacher's Activity Book Level 2 67 Date Like A Man: What Men Know About Dating and Are Afraid You'll Find Out 67 Reading and Writing Targets: Student's Book Level 2 64 Fairyland 1 : Activity Book 64 Introducere în psihologie 60 Fairyland 2 : Activity Book 56 Reading and Writing Targets: Student's Book Level 1