def recuperaPosts(fol, hashtags): """ Funció que s'utilitza per recuperar els posts a partir del directori / fitxer on hi són guardats. :param fol: El nom del directori on hi haurà el fitxer de Posts per poder-ne extreure la informació :param hashtags: Diccionari de :class:`Hashtags.Hashtag` existents en la xarxa social :return: False si no s'ha pogut fer correctament i llista de posts si sí que s'ha pogut realitzar la recuperació correctament """ posts = [] try: for post in ReadWriteFiles.readlines(fol, ReadWriteFiles.NomFitPosts): p = Post() if (not p.recupera(post, hashtags)): raise Exceptions.PostError() else: posts.append(p) except Exceptions.PostError: print "El post no s'ha pogut convertir correctament" return False except Exception as e: print e return False return posts
def readFile(folder): """ Llegeix el fitxer dins del directori :param folder: Directori on hi ha el fitxer ROM :return: El txt amb tot el text """ l = ReadWriteFiles.readlines(folder, ReadWriteFiles.ORIGINAL) return [line.split() for line in l] if l != False else exit()
def readFile(folder): """ Llegeix el fitxer dins del directori :param folder: Directori on hi ha el fitxer ROM :return: El txt amb tot el text """ l = ReadWriteFiles.readlines(folder, ReadWriteFiles.ROM) return l if l != False else exit()
def recuperaHashtags(fol): """ Funció per recuperar els hashtags a partir del directori on hi ha el fitxer que guarda la informació d'aquests :param fol: El nom del directori on hi haurà el fitxer de Posts per poder-ne extreure la informació :return: False si no s'ha pogut fer la conversió correctament i una llista de Hashtags si s'ha pogut fer correctament """ hash = [] try: for h in ReadWriteFiles.readlines(fol, ReadWriteFiles.NomFitHashtags): hash.append(Hashtag(h)) except Exception as e: print "Error, no s'ha pogut recuperar els hashtags correctament: ", e.message return False return hash
def recuperaUsuaris(fol, posts): """ Funció que s'utilitza per recuperar els usuaris a partir del directori / fitxer on hi són guardats. :param fol: El nom del directori on hi haurà el fitxer de Posts per poder-ne extreure la informació :param posts: Diccionari de :class:`Posts.Post` existents en la xarxa social :return: False si no s'ha pogut fer correctament i diccionari d'usuaris si sí que s'ha pogut realitzar la recuperació correctament """ usuaris = {} try: for user in ReadWriteFiles.readlines(fol, ReadWriteFiles.NomFitUsuaris): u = User() if (not u.recupera(user, posts)): raise Exceptions.UserError() else: usuaris[u.nick] = u except Exceptions.UserError: print "L'usuari no s'ha pogut convertir correctament" return False except Exception as e: print e return False try: for usuari in usuaris.values(): followersInstance = [] for follower in usuari.followers: if (follower == ""): continue if (follower not in usuaris): raise Exceptions.NoUserException(follower) else: followersInstance.append(usuaris[follower]) usuari.followers = followersInstance except Exceptions.NoUserException as e: print "No hi ha cap usuari anomenat", e.message, "en la xarxa social" return False except Exception as e: print "Excepció al posar followers: ", e.message return False try: for usuari in usuaris.values(): followingInstance = [] for following in usuari.following: if (following == ""): continue if (following not in usuaris): raise Exceptions.NoUserException(following) else: followingInstance.append(usuaris[following]) usuari.following = followingInstance except Exceptions.NoUserException as e: print "No hi ha cap usuari anomenat", e.message, "en la xarxa social" return False except Exception as e: print "Excepció al posar following: ", e.message return False return usuaris