Skip to content

bug 2 #1220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: feedback-fix
Choose a base branch
from
Open

bug 2 #1220

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4c96f43
updated header
mrudhvika940 Mar 22, 2020
a535024
updated header ans footer
mrudhvika940 Mar 24, 2020
07eef5c
Merge pull request #1158 from virtual-labs/header_and_footer
mrudhvika940 Mar 24, 2020
d31ac76
fix: experiments
ojas1 Jul 1, 2020
35321a1
update makefile to modify patch analytics
ojas1 Jul 2, 2020
7a6e77d
fix theory and intro
ojas1 Jul 3, 2020
5b42614
deleting submissions
ojas1 Jul 3, 2020
8b45cd8
changelog
ojas1 Jul 3, 2020
0ac357c
remove analytics from src
ojas1 Jul 3, 2020
47e938f
links update
ojas1 Jul 8, 2020
f012eed
fixed feedback links
sravanthimodepu Jan 8, 2021
14c84bd
added vlead logo
sravanthimodepu Jan 19, 2021
a2f9a96
Merge pull request #1222 from virtual-labs/css-fix
sravanthimodepu Jan 22, 2021
0b95c81
fixed compile issue
balamma Sep 21, 2021
75ff197
removed conflicts
balamma Dec 15, 2021
833d635
updated Hint files for the simulation
sravanthimodepu Dec 15, 2021
e1de930
updated hint files for the simulations
sravanthimodepu Dec 15, 2021
e0055b1
updated hint files for the simulations
sravanthimodepu Dec 15, 2021
9457245
updated hint files for the simulations
sravanthimodepu Dec 15, 2021
4e9d729
updated hint files for the simulations
sravanthimodepu Dec 15, 2021
cfca94c
updated hint files for the simulations
sravanthimodepu Dec 15, 2021
61c3246
updated all the hints
sravanthimodepu Dec 16, 2021
b58adc9
updated all the hints
sravanthimodepu Dec 16, 2021
433b129
updated all the hints
sravanthimodepu Dec 16, 2021
75acc6a
fixed broken links in all the pages
sravanthimodepu Dec 17, 2021
b81fc89
Merge pull request #1225 from virtual-labs-archive/fix/experiment
sravanthimodepu Dec 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ template1.html
scrap.py
scraplab.py
*~
content.html
content.html
submission*.html
1 change: 0 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,3 @@ Go to Command Terminal
$ make theme=blue-icon

* Now, open ui/build/index.html in the browser to test the template.

21 changes: 21 additions & 0 deletions changelog.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#+NAME: Changelog

* <2020-07-03 Fri>

- Author :: Ojas Mohril
- Changes ::
- Updated makefile =patch-analytics= command to use
=scripts/patch-analytics.sh= instead of the script
from [[https://github.com/virtual-labs/vlabs-analytics][vlabs-analytics]].
- This script is taken from the [[https://github.com/virtual-labs/vlabs-analytics][vlabs-analytics]] repo but updated
to ignore =content*.html= files. Justification for why this is
needed can be found in [[https://github.com/virtual-labs/problem-solving-iiith/issues/1213][this]] issue. (In brief, content*.html
files are not really html and break when touched by the
analytics code.)
- As a result of this change, the submission files will no longer
have analytics snippet and these page views will not be tracked.
- Removed all committed submission*.html files and added the
pattern to gitignore. These are radomly generated files and
should not be added to version control.
- As the broken content files were comitted at some point on the
master, the working files had to extracted from [[https://github.com/virtual-labs/problem-solving-iiith/commit/591c7f3c91d260a9a0ef12385c62be3b63577e44][this]] commit.
110 changes: 110 additions & 0 deletions scripts/gtm-patcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/python

from bs4 import BeautifulSoup, Tag, Comment
import sys

headSnippet = """(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-W59SWTR');"""

iframeSrc = "https://www.googletagmanager.com/ns.html?id=GTM-W59SWTR"


insert_head = "<script class='gtm'>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-W59SWTR');</script>"
def patch_php(filepath):
# print(filepath)
try:
if(1):
f1 = open(filepath,"r")
lines = f1.readlines()
string_inserted = ''
for line in lines:
if("<script class='gtm'>" in line):
return
f1.close()
if(1):
# print(filepath)
f1 = open(filepath,"r")
lines = f1.readlines()
# print(lines)
string_inserted = ''
for line in lines:
if('<head>' in line):
line = line.split('<head>')
temp_string = line[0]
temp_string+='<head>\n'
temp_string+=insert_head+'\n'
for i in line[1:]:
temp_string+=i
line = temp_string
string_inserted+=line
print(string_inserted)
f1.close()
f = open(filepath,"w")
f.write(string_inserted)
f.close()

except IOError as e:
print "I/O error({0}): {1}".format(e.errno, e.strerror)
return -1
except:
print "Unexpected error:", sys.exc_info()[0]
return -2
print "Analytics Patched Successfully"
return 0

# load the file
def patch(filepath):
if("php" in filepath):
patch_php(filepath)
return 0
try:
with open(filepath) as inf:
txt = inf.read()
# soup = BeautifulSoup(txt, 'html.parser')
soup = BeautifulSoup(txt, "html5lib")
mydiv = soup.head.find('script', { 'class': 'gtm' })
if not mydiv:
scrTag = Tag(soup, name = 'script')
scrTag['class'] = "gtm"
scrTag.string = headSnippet
soup.head.insert(0, Comment('End Google Tag Manager'))
soup.head.insert(0, scrTag)
soup.head.insert(0, Comment('Google Tag Manager'))
#scrTag.insert_before(Comment('Google Tag Manager'))
#scrTag.insert_after(Comment('End Google Tag Manager'))

# insert body snippet into the document
iframeTag = Tag(soup, name = 'iframe')
iframeTag['src'] = iframeSrc
iframeTag['height'] = "0"
iframeTag['width'] = "0"
iframeTag['style'] = "display:none;visibility:hidden"

noscrTag = Tag(soup, name = 'noscript')
noscrTag['class'] = 'gtm'
noscrTag.insert(0, iframeTag)
soup.body.insert(0, Comment('End Google Tag Manager (noscript)'))
soup.body.insert(0, noscrTag)
soup.body.insert(0, Comment('Google Tag Manager (noscript)'))
#noscrTag.insert_before(Comment('Google Tag Manager (noscript)'))
#noscrTag.insert_after(Comment('End Google Tag Manager (noscript)'))

# save the file again
with open(filepath, 'w') as outf:
outf.write(str(soup))

except IOError as e:
print "I/O error({0}): {1}".format(e.errno, e.strerror)
return -1
except:
print "Unexpected error:", sys.exc_info()[0]
return -2
print "Analytics Patched Successfully " + filepath
return 0


if __name__=='__main__':
patch(sys.argv[1])
22 changes: 22 additions & 0 deletions scripts/patch-analytics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# This command applies the gtm-patcher.py script to each html and php file
# recursively in the directory where it is executed. As this intended
# applying analytics code to each lab and experiment file, this script
# should be executed in the src/ directory.

# Any html file that starts with 'content' in its name, will be ignored
# by the script as applying the script to these files breaks the page
# structure.

# The gtm-patcher.py file comes from vlabs-analytics project which
# can be found here: https://github.com/virtual-labs/vlabs-analytics

# NOTE: This command will change the src files.

find . -type f \
\( \
\( -name "*.html" -or -name "*.php" \) \
! -name "content*.html" \
\) \
-exec ../scripts/gtm-patcher.py {} \;
Loading