Ejemplo n.º 1
0
def home(request, acc):
    if acc == request.user.username:
        user = Member.objects.get(usr=User.objects.get(
            username=request.user.username))
        if user.university == "":
            unis = list(universities.API().search(country="United Kingdom"))
            uni_names = []
            for uni in unis:
                uni_names.append(uni.name)
            return render(
                request, 'projectlab/home.html', {
                    'user': user,
                    'all_projects':
                    user.project_set.all().order_by('deadline'),
                    'today': datetime.datetime.now(),
                    'uni_names': uni_names
                })
        else:
            return render(
                request, 'projectlab/home.html', {
                    'user': user,
                    'all_projects':
                    user.project_set.all().order_by('deadline'),
                    'today': datetime.datetime.now()
                })
    else:
        return HttpResponseRedirect(reverse('projectlab:login'))
Ejemplo n.º 2
0
def AddressDetail(TakeList, q, TakeOutFilePath):
    driver = GetBrowser()
    try:
        result = []
        FileOut = open(TakeOutFilePath, 'a')
        for line in TakeList:
            resultToWrite = []
            uni = universities.API(
            )  # can specify encoding for use in Python 2
            line = line.strip("\n")
            SplitLine = line.split("\t")
            Splittext = SplitLine[1].split("#")
            if len(Splittext) == 1:
                Splittext[0] = Splittext[0].replace("b'", "b' ")
                Splittext[0] = Splittext[0].replace('b"', 'b" ')
            for value in Splittext:
                try:
                    value = value.split(" ", 1)[1]
                except:
                    value = value
                value = value.replace(";", "")
                value = value.replace("'", "")
                link = 'https://www.google.com/maps/search/' + value
                '''link='https://en.wikipedia.org/wiki/'+value #for wikipedia '''
                #print (link)
                driver.get(str(link))
                time.sleep(5)
                try:
                    page = soup(driver.page_source, 'html.parser')
                    content = page.findAll('jsl', {'jstcache': '87'})
                    '''content = driver.find_elements_by_class_name('country-name')
					for data in content:
						stringToAppend=str(value)+": address: "+str(data.text)
						resultToWrite.append(stringToAppend)'''
                    for tag in content:
                        divTag = tag.find_all(
                            "div",
                            {"class": "ugiz4pqJLAG__primary-text gm2-body-2"})
                        for tag in divTag:
                            stringToAppend = str(value) + ": address: " + str(
                                tag.text)
                            resultToWrite.append(stringToAppend)
                            break
                except:
                    stringToAppend = str(value) + " :address: " + str("NA")
                    resultToWrite.append(stringToAppend)
                    pass
            FileOut.write(
                str("\t".join(line.split("\t", 2)[:2])) + "\t" +
                str(len(resultToWrite)) + "\t" + str("#".join(resultToWrite)) +
                "\n")
        result.append("Done")
        FileOut.close()
        driver.close()
    except:
        q.put([])
        raise
    q.put(result)
Ejemplo n.º 3
0
def get_country_from_domain(domain):
    try:
        country = None
        uniapi = universities.API()
        for u in uniapi.search(domain=domain):
            if domain in u.domains:
                country = u.country
                break
        return country
    except:
        return None
Ejemplo n.º 4
0
 def __init__(self, config_path):
     self.uni = universities.API()
     self.reg = r".*(\s+\w+\s+University).*"
     self.config = Config(config_path)
     self.mongo = Mongo(config_path)
     self.collection = 'data'
     self.minimum_length = int(
         self.config.getValueDefault('Data', 'MINLENGTH', 400))
     self.max_items = int(self.config.getValue('Data', 'ITEMS'))
     self.start = int(self.config.getValue('Data', 'START'))
     if not self.max_items:
         raise Exception('Please set max_items inside config.ini')
Ejemplo n.º 5
0
class RegistrationForm(Form):  # inherit from wtform.Form
    username = TextField('Username', [validators.Length(min=4, max=50)])
    password = PasswordField('Password', [
        validators.DataRequired(),
        validators.EqualTo('confirm', message='Passwords do not match.')
    ])
    confirm = PasswordField('Repeat Password')
    tzs = pytz.common_timezones
    tzs.append('NA')
    timezone = SelectField(label='Timezone(optional)',
                           choices=tzs,
                           default="NA")
    unis1 = [
        uni.name for uni in universities.API().search(country="United States")
    ]
    unis2 = [uni.name for uni in universities.API().search(country="Canada")]
    unis = sorted(unis1 + unis2)
    unis.append('NA')
    university = SelectField(label='University(optional)',
                             choices=unis,
                             default="NA")
Ejemplo n.º 6
0
 def update_institute(event, self):
     if len(list2) > 0:
         list2.clear()
     string = self.Country.get()
     print(string)
     uni = universities.API()
     init = uni.search(country=string)
     for i in init:
         list2.append(i.name)
     self.label_institute.config(value=list2)
     val = pycountry.countries.get(name=string)
     for k, vs in phonenumbers.COUNTRY_CODE_TO_REGION_CODE.items():
         if vs[0] == val.alpha_2:
             code = "+" + str(k)
     self.phonecode.set(code)
Ejemplo n.º 7
0
def verify_sign_up(request):
    if request.method == "POST":
        try:
            username = Member.objects.get(usr=User.objects.get(
                username=request.POST['signup_username']))
        except ObjectDoesNotExist:

            try:
                email = Member.objects.get(usr=User.objects.get(
                    email=request.POST['email']))
            except ObjectDoesNotExist:
                addr = request.POST['email'].split('@')[1]
                domain = re.search("\w+.ac.uk$", addr)
                if not domain:
                    return HttpResponseServerError(
                        "<strong>The email address you have provided does not belong to a valid institution<strong>"
                    )
                selected_uni = ""
                uni = list(universities.API().search(domain=domain.group()))
                if uni:
                    selected_uni = uni[0].name
                Member(usr=User.objects.create_user(
                    username=request.POST['signup_username'],
                    password=request.POST['signup_password'],
                    email=request.POST['email'],
                    first_name=request.POST['firstName'],
                    last_name=request.POST['lastName']),
                       dob=datetime.datetime.strptime(
                           request.POST['dob'],
                           "%d/%m/%Y").strftime("%Y-%m-%d"),
                       university=selected_uni).save()
                return HttpResponse("<strong>Sign up successful!<strong>")
            else:
                return HttpResponseServerError(
                    "<strong>The email address you have provided is already in use. Please try another address<strong>"
                )
        else:
            return HttpResponseServerError(
                "<strong>The username you have provided is already in use. Please try another name<strong>"
            )
Ejemplo n.º 8
0
import dialogflow_v2 as dialogflow
dialogflow_session_client = dialogflow.SessionsClient()
PROJECT_ID = "unibotagent-yqjsuh"

import universities
from pymongo import MongoClient
client = MongoClient(
    "mongodb+srv://bot:[email protected]/test?retryWrites=true&w=majority"
)
db = client.get_database('bot_data')
records = db.user_query

import wikipedia

uni = universities.API()


def getUniv(parameters):
    uniName = parameters.get('univ_name')
    records.insert_one({"User Query: ": str(parameters)})
    #myUniv = uni.lucky(name=uniName)
    return uniName


def getLoc(parameters):
    records.insert_one({"User Query: ": str(parameters)})
    univ = parameters.get('geo-country')
    print("Univ Name is: " + str(univ))
    #data = uni.search(country = univ)
    return univ