Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021-090
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2021-090
2021-090
Commits
6cf873f1
Commit
6cf873f1
authored
Nov 05, 2021
by
IT18111170-Silva S.H.I
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit" after pp2 update
parent
26c04af0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
111 additions
and
27 deletions
+111
-27
Agri_Backend/Agripreneur_App/Routes/Gamification.py
Agri_Backend/Agripreneur_App/Routes/Gamification.py
+1
-1
Agri_Backend/Agripreneur_App/Routes/Leaderboard.py
Agri_Backend/Agripreneur_App/Routes/Leaderboard.py
+60
-17
Agri_Backend/Agripreneur_App/Routes/PricePage.py
Agri_Backend/Agripreneur_App/Routes/PricePage.py
+9
-3
Agri_Backend/Agripreneur_App/Routes/User.py
Agri_Backend/Agripreneur_App/Routes/User.py
+37
-5
Agri_Backend/Main.py
Agri_Backend/Main.py
+4
-1
No files found.
Agri_Backend/Agripreneur_App/Routes/Gamification.py
View file @
6cf873f1
...
...
@@ -22,7 +22,7 @@ def add_points_earns(id):
# area_earn = request.form.get("earns")
earns
=
8
000
earns
=
50
000
# points calculation algorithm
if
earns
>=
5000
:
points
=
10
...
...
Agri_Backend/Agripreneur_App/Routes/Leaderboard.py
View file @
6cf873f1
import
pymongo
from
extensions
import
mongo
,
db
from
Main
import
app
from
flask
import
Response
,
request
...
...
@@ -33,22 +34,42 @@ def get_point_redis():
user_earns
=
db
.
CropData
.
find
()
descodr
=
db
.
CropData
.
find
()
.
sort
(
"earns"
,
pymongo
.
DESCENDING
)
print
(
user_earns
)
for
user
in
user_earns
:
# user["_id"] = str(user["_id"])
user
[
"_id"
]
=
str
(
user
[
"userID"
])
earnsbyUsr
=
user
[
"earns"
]
redisClient
.
zadd
(
earn_gain
,
{
user
[
"_id"
]:
earnsbyUsr
})
# print(earnsbyUsr)
# print(user["_id"])
print
(
"Contents of the Redis sorted set with scores:"
)
response
=
redisClient
.
zrange
(
earn_gain
,
0
,
-
1
,
desc
=
True
,
withscores
=
True
)
print
(
response
)
print
(
descodr
)
users
=
[]
for
user
in
descodr
:
# print(user)
users
.
append
(
user
)
# resp = user
# my_json = response.decode('utf-8')
return
Response
(
response
=
json
.
dumps
({
"message"
:
json
.
loads
(
dumps
(
users
))}),
status
=
200
,
)
# for user in user_earns:
# # user["_id"] = str(user["_id"])
# user["_id"] = str(user["userID"])
# earnsbyUsr = user["earns"]
# redisClient.zadd(earn_gain, {user["_id"]: earnsbyUsr})
# # print(earnsbyUsr)
# # print(user["_id"])
# print("Contents of the Redis sorted set with scores:")
# response = redisClient.zrange(earn_gain, 0, -1, desc=True, withscores=True)
# print(response)
# my_json = strn.decode('ascii')
# print(my_json)
# stringOBJ = convertTuple(response)
...
...
@@ -57,11 +78,33 @@ def get_point_redis():
# data = json.loads(my_json)
return
Response
(
response
=
json
.
dumps
({
"message"
:
json
.
loads
(
dumps
(
response
))}),
status
=
200
,
# function covertObjectToBinary(obj) {
# let output = '',
# input = JSON.stringify(obj) // convert the json to string.
# // loop over the string and convert each charater to binary string.
# for (i = 0; i < input.length; i++) {
# output += input[i].charCodeAt(0).toString(2) + " ";
# }
# return output.trimEnd();
# }
)
# def()
# for obj in response:
# bObject = user["_id"]
# my_json = bObject.decode('utf8')
# print(my_json)
# data = json.loads(my_json)
# print(json.dumps(data))
# return Response(
# response= json.dumps({"message": json.loads(dumps(response))}),
# status=200,
# )
# @app.route("/users", methods=["POST"])
...
...
Agri_Backend/Agripreneur_App/Routes/PricePage.py
View file @
6cf873f1
from
extensions
import
mongo
,
db
from
Main
import
app
from
flask
import
Response
,
request
from
flask
import
Response
,
request
,
send_from_directory
# import pymongo
import
json
from
bson.objectid
import
ObjectId
from
Agripreneur_App.Auth.Token
import
check_for_token
from
bson.json_util
import
dumps
import
os
# from json import stringify
@
app
.
route
(
"/getimage/<filename>"
,
methods
=
[
"GET"
])
# @check_for_token
def
get_image
(
filename
):
print
(
request
.
headers
)
root_dir
=
os
.
path
.
dirname
(
os
.
getcwd
())
print
(
root_dir
)
return
send_from_directory
(
os
.
path
.
join
(
root_dir
,
"Agri_Backend"
),
filename
,
as_attachment
=
True
)
@
app
.
route
(
"/discount/<id>"
,
methods
=
[
"GET"
])
...
...
Agri_Backend/Agripreneur_App/Routes/User.py
View file @
6cf873f1
from
extensions
import
mongo
,
db
from
Main
import
app
from
Main
import
app
,
UPLOAD_FOLDER
,
ALLOWED_EXTENSIONS
import
base64
# from flask import Blueprint
from
flask
import
Response
,
request
,
session
...
...
@@ -11,26 +11,58 @@ import json
from
bson.objectid
import
ObjectId
from
Agripreneur_App.Auth.Token
import
check_for_token
from
werkzeug.security
import
generate_password_hash
,
check_password_hash
from
werkzeug.utils
import
secure_filename
# from werkzeug.datastructures import ImmutableMultiDict
import
os
# considered about image upload of user
# considered about image upload of user
# allowed files
def
allowed_file
(
filename
):
return
'.'
in
filename
and
\
filename
.
rsplit
(
'.'
,
1
)[
1
]
.
lower
()
in
ALLOWED_EXTENSIONS
# ====Routes====
# ====Upload image====
# @app.route("/users", methods=["POST"])
# def upload_img():
# print(request)
# ====Routes====
# ====post users====
@
app
.
route
(
"/users"
,
methods
=
[
"POST"
])
def
create_user
():
print
(
request
)
print
(
request
.
form
)
try
:
password
=
request
.
form
.
get
(
"password"
)
hashed_value
=
generate_password_hash
(
password
,
method
=
'sha256'
)
# profile_image = request.form.get("img")
profile_image
=
request
.
form
[
"img"
]
print
(
profile_image
+
"==========="
)
imgdata
=
base64
.
b64decode
(
profile_image
)
# if profile_image and allowed_file(profile_image.filename):
filename
=
secure_filename
(
profile_image
)
print
(
filename
)
# imgdata.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
with
open
(
filename
,
'wb'
)
as
f
:
f
.
write
(
imgdata
)
# if 'profile_image' in request.files:
# image_string = base64.b64encode(profile_image.read())
# db.images.save_file(profile_image.filename, profile_image)
user
=
{
"name"
:
request
.
form
.
get
(
"name"
),
"email"
:
request
.
form
.
get
(
"email"
),
"password"
:
hashed_value
,
"district"
:
request
.
form
.
get
(
"district"
)}
"district"
:
request
.
form
.
get
(
"district"
),
"prof_img_name"
:
filename
}
dbResponse
=
db
.
users
.
insert_one
(
user
)
print
(
user
)
print
(
dbResponse
.
inserted_id
)
...
...
Agri_Backend/Main.py
View file @
6cf873f1
from
flask
import
Flask
from
flask_cors
import
CORS
UPLOAD_FOLDER
=
'./Agripreneur_App/images'
ALLOWED_EXTENSIONS
=
{
'txt'
,
'pdf'
,
'png'
,
'jpg'
,
'jpeg'
,
'gif'
}
app
=
Flask
(
__name__
)
CORS
(
app
)
app
.
config
[
'SECRET_KEY'
]
=
"testing12#"
app
.
config
[
'UPLOAD_FOLDER'
]
=
UPLOAD_FOLDER
# from Agripreneur_App.Routes.Agri_App import create_user
# from extensions import mongo, db
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment