Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ShreyamMaity committed Nov 15, 2021
0 parents commit c1aa76e
Show file tree
Hide file tree
Showing 6 changed files with 346 additions and 0 deletions.
130 changes: 130 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Byte-compiled / optimized / DLL files
__pycache__/
assignmenty
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Assignmenty
Just Code and Push , Leave The Assignment Part on us....
18 changes: 18 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Assignmenty Bot
author: Shreyam Maity
description: Just Code and Push , Leave The Assignment Part on us....
inputs:
mailId :
description: 'your mail id where you want to recieve the assignment'
required: true
fileName :
description: 'Filename of your assignment'
required: true
runs:
using: docker
image: 'docker://shreyammaity/assignmenty'

# for publishing purposes
branding:
icon: check-square
color: blue
17 changes: 17 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
google-api-core==1.31.0
google-api-python-client==2.29.0
google-auth==1.33.0
google-auth-httplib2==0.1.0
google-auth-oauthlib==0.4.6
google-cloud-core==2.1.0
google-cloud-firestore==2.3.4
google-cloud-storage==1.42.3
google-cloud-texttospeech==2.7.1
google-crc32c==1.3.0
google-resumable-media==2.1.0
googleapis-common-protos==1.53.0
oauth2client==4.1.3
oauthlib==3.1.1
PyGithub==1.55
python-dateutil==2.8.2
python-docx==0.8.11
179 changes: 179 additions & 0 deletions script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
from __future__ import print_function
import os
import base64
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
import subprocess
import mimetypes
import docx
import glob
from datetime import datetime
import re

def auth():
SCOPES = ['https://www.googleapis.com/auth/gmail.send']
creds = None
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file('token.json', SCOPES)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
with open('token.json', 'w') as token:
token.write(creds.to_json())

service = build('gmail', 'v1', credentials=creds)
return service

def mailSender(assignment, subject, body, mail):
service = auth()
file_attachements = [r'./'+ assignment +'.docx']
emailMsg = subject
Message = MIMEMultipart()
Message['to'] = mail
Message['subject'] = body
Message.attach(MIMEText(emailMsg, 'plain'))

for attachement in file_attachements:
content_type, encoding = mimetypes.guess_type(attachement)
main_type, sub_type = content_type.split('/', 1)
file_name = os.path.basename(attachement)

f = open(attachement, 'rb')

myFile = MIMEBase(main_type, sub_type)
myFile.set_payload(f.read())
myFile.add_header('Content-Disposition',
'attachement', filename=file_name)
encoders.encode_base64(myFile)

f.close()

Message.attach(myFile)
raw_string = base64.urlsafe_b64encode(Message.as_bytes()).decode()
message = service.users().messages().send(userId='me', body={'raw': raw_string}).execute()
print('Message Id: %s' % message['id'])

def getCommitFiles():
files = subprocess.check_output(['git', 'diff-tree', '--no-commit-id', '--name-only', '-r', 'HEAD']).decode('utf-8').split('\n')
return files

def getPyFiles(fileList):
pyFiles = []
sort = {}
for file in fileList:
if file.endswith('.py'):
m = re.search(r'\d+$', file.replace('.py', ''))
if m:
sort[m.group()] = file
for k, v in sorted(sort.items(), key=lambda x: int(x[0])):
pyFiles.append(v)
return pyFiles

def getQuestions(fileList):
questions = {}
for file in fileList:
with open(file, 'r') as f:
for line in f:
if line.startswith('\'\'\''):
questions[re.search(r'\d+$', file.replace('.py', '')).group()] = line.replace('\'\'\'', '').strip()
return questions

def getRunSnaps(fileList):
runSnaps = []
sort = {}
try :
for file in fileList:
if file.endswith('.png'):
m = re.search(r'\d+$', file.replace('.png', ''))
if m:
sort[m.group()] = file
for k, v in sorted(sort.items(), key=lambda x: int(x[0])):
runSnaps.append(v)
return runSnaps
except:
for file in fileList:
if file.endswith('.jpg'):
m = re.search(r'\d+$', file.replace('.jpg', ''))
if m:
sort[m.group()] = file
for k, v in sorted(sort.items(), key=lambda x: int(x[0])):
runSnaps.append(v)
return runSnaps

def getTime():
return datetime.now().strftime("%d/%m/%Y")

def buildPdf(assignment, questions, snaps, template, fileName):
doc = docx.Document()
base = docx.Document(template)
for para in base.paragraphs:
if para.text.find('Date of')!=-1:
para.text += getTime()
bc = doc.add_paragraph(para.text)
bc.bold = True
bc.alignment = para.alignment
bc.style = para.style
doc.add_paragraph("_________________________________________________________________________________________________________")
for key, value in questions.items():
quesNo = doc.add_paragraph()
quesNo.add_run("Question No: ").bold = True
quesNo.add_run(key)
quesNo.style = 'List Number'

ques = doc.add_paragraph()
ques.add_run("Question: \t").bold = True
ques.add_run(value)
ques.style = 'List Bullet'
for code in assignment:
if key in code:
with open(code, 'r') as f:
data = f.read()
code = doc.add_paragraph()
code.add_run("Code: \n\n").bold = True
code.add_run(data)
code.style = 'List Bullet'
for snap in snaps:
if key in snap:
tit = doc.add_paragraph()
tit.add_run("Snapshot: \n\n").bold = True
tit.style = 'List Bullet'
doc.add_picture(snap, width=docx.shared.Cm(16),height=docx.shared.Inches(2))

doc.add_paragraph("_________________________________________________________________________________________________________")
doc.add_paragraph('\n\nAuto Generated with Assignmenty Bot. Check me out on github: github.com/ShreyamMaity/Assignmenty').alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.CENTER
doc.save(fileName + '.docx')

def removeFiles(pdfName):
if os.path.exists(pdfName + '.docx'):
os.remove(pdfName + '.docx')
for file in glob.glob("*.png"):
os.remove(file)

def main():

mailId = os.environ['INPUT_MAILID']
fileName = os.environ['INPUT_FILENAME']
fileList = getCommitFiles()
pyFiles = getPyFiles(fileList)
questions = getQuestions(pyFiles)
snaps = getRunSnaps(fileList)
buildPdf(pyFiles, questions, snaps, 'template.docx' , fileName)
mailSender(fileName, 'Your Assignment Is here', 'Hello User, Thanks for using Assignment Bot. Hope You love our sevice 😊\n', mailId)
removeFiles(fileName)




if __name__ == '__main__':
main()
Binary file added template.docx
Binary file not shown.

0 comments on commit c1aa76e

Please sign in to comment.