Пример #1
0
def upload_contacts_file(request):
    """
    Uploads a file to a server
    Responds with:
    - Mapping contactinfo types
    - List of n rows specified by a request param "rows"
    - Filename in the system
    """
    n_rows = request.GET.get('rows', 1)
    uploaded_file = request.FILES['myfile']
    filename = str(uuid4()).replace('-', '')
    save_path = os.path.join(CONTACTS_FILES_DIR, filename)

    with open(save_path, 'wb+') as saved_file:
        for chunk in uploaded_file.chunks():
            saved_file.write(chunk)

    decoded_file = uploaded_file.read().decode('utf-8').splitlines()
    reader = csv.Reader(decoded_file)
    returned_rows = [row for row in reader[0: n_rows]]

    return JsonResponse({
        'filename': filename,
        'returned_rows': returned_rows,
        'mapped_contact_types': CONTACT_INFO_TYPES,
    })
Пример #2
0
def readCsvToList(filename):
    file = open(filename, encoding="utf-8")
    dataset = []
    reader = csv.Reader(file)
    for i in reader:
        dataset.append(i)  # reading to dict
    return dataset
Пример #3
0
    def import_grades(self,
                      name,
                      gfile,
                      points_possible=None,
                      matching=False,
                      weight=1.0):
        """import grades from file.

		Parameters
		----------
		name : str
			Name of the assignment which is being added
		gfile : str
			Full path to .csv file containing grades
		points_possible : float, int, or None
			Number of points possible (Default value = None)
		matching : bool
			Matches grades to students in roster if an exact match doesn't exist (Default value = False)
		weight : float
			Weight to apply to assignment (Default value = 1.0)

		Returns
		-------

		"""

        self.grades['Entries'].append(name)
        self.grades['Points Possible'].append(points_possible)
        self.grades['Weights'].append(weight)

        tmp_grades = {}
        with open(gfile, "r") as f:
            reader = csv.Reader(f)
            for row in reader:
                try:
                    lastname = self.roster[row[0]][row[1]]['Last Name']
                    firstname = self.roster[row[0]][row[1]]['First Name']
                except KeyError:
                    if matching:
                        lastname, firstname = self.roster.match(row[0], row[1])
                        if (lastname, firstname) in tmp_grades.keys():
                            continue
                    else:
                        continue

                tmp_grades[lastname, firstname] = float(row[2])

        for student in self.roster.studentlist:
            lastname = student['Last Name']
            firstname = student['First Name']
            score = 0
            try:
                score = tmp_grades[lastname, firstname]
            except KeyError:
                pass
            self.grades["Students"][lastname,
                                    firstname]["Scores"].append(score)
            self.grades["Students"][lastname, firstname][name] = score
            self.grades["Students"][lastname, firstname]["Total"] += score
Пример #4
0
def Berkeley_Arts_Magnet():
	with open('BUILD_SiteTimes2.csv') as g:
		site_times = csv.Reader(g)
		BAM_avail = {}		
		for site from site_times
			start_time = []
			start_time = list.site['Mond']
			BAM_avail = dict.fromkeys(days)
    def handle(self, *args, **options):
        file_path = options['squirrel_file']

        try:
            with open(file_path) as f:
                reader = csv.Reader(f)
                for item in reader:
                    #item
                    pass
            msg = f'You are importing from {file_path}'
            self.stdout.write(self.style.SUCCESS(msg))

        except:
            raise CommandError('Import file failed')
Пример #6
0
 def verifyLogin(self):
     #This is a routine which returns a bool value of true or false for the user's login
     #If true is returned, this means taht user will be able to login and will be greeted with an appropriate welcome screen. 
     #Otherwise the user will be told their login information is wrong and will be sent back to the login screen to try again. 
     file = open("usernames.txt","r")
     fr = csv.Reader(file)
     users = []
     for row in fr:
         for item in row:
             users.append(item)
     un = input("please enter your username")
     pw = input("please enter your password")
     for item in range(len(users[::3])):
         if users[item] == un and users[item+1] == hashlib.sha256(b(pw)).hexdigest():
             self.__name=un
             self.__ID=users[item+2]
             self.sessionToken=Token.Token(self.__ID)
             return True
     else:
         return False
Пример #7
0
def fetch_tsv_header(file_path):
    with open(file_path) as fin:
        reader = csv.Reader(fin, delimiter='\t')
        return next(reader)
Пример #8
0
# Budget Calendar
# To calculate how much money is available to spend daily to meet savings goals
# Variables:
#   Overall goal
#   Daily goal
#   Days until End
#   Balance
#   Daily Income
#   Deductions
#   Spending Limit
# Deductions Class
#   Bills
#   Money spent

#  Process: Balance = Balance + Daily income - Deductions
#   Daily goal = Overall goal / Days until End
#   Spending Limit = Balance - Daily goal

# Get inputs from file (???)
import csv
with open() as csvDataFile:
    csvReader = csv.Reader(csvDataFile)
    for column in csvReader:
        print(column)
    
Пример #9
0
 def reset(self):
     self.file.close()
     self.file = open(self.filename, 'r')
     self.file.readline()  #get rid of headers
     self.reader = csv.Reader(self.file)
Пример #10
0
import csv
import json
import networkx as nx  #Libreria de las redes
import matplotlib.pyplot as plt  #Libreria para la representacion de redes

jsonfile = open('file.json', 'w')

data = {}

csvfile = open('PDVR.csv', 'r')
reader = csv.Reader(csvfile)
mylist.append(reader)

for user in mylist.values():
    data[user] = []
    path = 'userdata/' + user + '.csv'
    fcsv = open(path, 'r')
    readerr = csv.Reader(csvfile)
    mylistt = list(readerr)
    for usefollower in mylistt.values():
        data[user].append(follower)

with open('data.txt', 'w') as outfile:
    json.dump(data, outfile)

# with open() as edge_list:
# data = json.load(edge_list)
# G = nx.Graph()

# for user in data['users']:
#     for follower in user['follower']
Пример #11
0
import numpy as np
import csv
from numpy import array, random
from scipy.cluster.vq import vq, kmeans, whiten

fl = open('SentiWordNet.csv', 'r');
csvReader = csv.Reader(fl, delimiter = ',');
features = np.asarray(list(csvReader));

features_n = [];
for feature in features:
	fea = [float(feature[0]), float(feature[1])]
	features_n.append(fea)

features = np.asarray(list(features_n));
whitened = whiten(features)

book = array((whitened[0],whitened[2]))
kmeans(whitened,book)

random.seed((1000,2000))
codes = 5
kmeans(whitened,codes)