WIP: Retrieve data from mediawiki for tools

This commit is contained in:
Adam Goldsmith 2022-10-05 13:58:42 -04:00
parent f7aeb280ab
commit b038e42542
3 changed files with 110 additions and 0 deletions

6
getWikiAssets.py Normal file
View File

@ -0,0 +1,6 @@
import requests
r = requests.get('https://wiki.claremontmakerspace.org/api.php?action=askargs&conditions=Asset Tag::%2B&printouts=Asset Tag|Requires Certification|Has Reservation URL&format=json&api_version=2')
with open('wiki-tools.json', 'w') as f:
f.write(r.text)

68
src/ToolsLabelText.vue Normal file
View File

@ -0,0 +1,68 @@
<template>
<span class="text-content">
<div class="name">{{ decodedName }}</div>
<!-- <div class="name">{{ asset.model.name }}</div> -->
<!-- ideas: model info? -->
<div class="certification">Certification: {{ certification }}</div>
<div class="reservation">Reservation: {{ reservation }}</div>
</span>
</template>
<script setup lang="ts">
import { computed, ComputedRef, defineProps } from 'vue';
import snipeit from './snipeit';
import mediawiki from './mediawiki';
import wikiTools from '../wiki-tools.json';
const props = defineProps<{
asset: snipeit.Hardware;
}>();
const decodedName: ComputedRef<string> = computed(() => {
const doc = new DOMParser().parseFromString(props.asset.name, 'text/html');
return doc.documentElement.textContent ?? 'invalid name!';
});
const wikiTool: ComputedRef<mediawiki.AskResult | undefined> = computed(() => {
return Object.values((wikiTools as mediawiki.apiAsk).query.results).find(
(x) => x.printouts['Asset Tag'].includes(props.asset.asset_tag)
);
});
const certification: ComputedRef<string> = computed(() => {
if (!wikiTool) {
return 'Unknown';
}
return (
wikiTool.value?.printouts[
'Requires Certification'
][0] as mediawiki.PageValue
).fulltext;
});
const reservation: ComputedRef<string> = computed(() => {
if (!wikiTool) {
return 'Unknown';
}
let reservationLinks = wikiTool.value?.printouts['Has Reservation URL'];
return reservationLinks && reservationLinks.length === 0 ? 'No' : 'Yes';
});
</script>
<style scoped>
.text-content {
font-family: monospace;
font-size: 10px;
line-height: 1;
}
.name {
text-decoration: underline;
}
.certification {
font-size: 10px;
}
</style>

36
src/mediawiki.d.ts vendored Normal file
View File

@ -0,0 +1,36 @@
export interface PrintRequest {
label: string;
key: string;
redi: string;
typeid: string;
mode: number;
}
export interface PageValue {
fulltext: string;
fullurl: string;
namespace: number;
exists: string; // TODO: might be '0'|'1'
displaytitle: string;
}
// TODO: more prop types exist
export type PropValue = string | PageValue;
export interface AskResult {
printouts: {
[prop: string]: PropValue[];
};
fulltext: string;
fullurl: string;
namespace: number;
exists: string; // TODO: might be '0'|'1'
displaytitle: string;
}
export interface apiAsk {
query: {
printrequests: PrintRequest[];
results: { [name: string]: AskResult };
};
}